package com.ynet.middleground.user.model;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.middleground.user.service.impl.EsignServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynet.cache.redis.IfpRedisson;
import com.ynet.core.common.PagerInfo;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.bean.*;
import com.ynet.middleground.user.common.ErrorMessageConstant;
import com.ynet.middleground.user.common.SystemConstant;
import com.ynet.middleground.user.dao.*;
import com.ynet.middleground.user.dto.*;
import com.ynet.middleground.user.entity.*;
import com.ynet.middleground.user.external.cloudPlatform.CloudPlatformConfig;
import com.ynet.middleground.user.mq.producer.ZtProducer;
import com.ynet.middleground.user.utils.BeanUtil;
import com.ynet.middleground.user.utils.CloudPlatformUtil;
import com.ynet.middleground.user.utils.CommUtils;
import com.ynet.middleground.user.utils.GeneralService;

/**
 * @program: 2019-10-12_userCenter
 * @description: 用户管理模块事务
 * @author: DaiGaoLe
 * @create: 2019-10-23 16:52
 **/
@Component
public class UserModel extends ServiceImpl<UserBaseInformationMapper, UserBaseInformation> {

    @Autowired
    private Mapper mapper;

    @Autowired
    private InviteeInformationMapper inviteeInformationMapper;

    @Autowired
    private EnterpriseUserInfoMapper enterpriseUserInfoMapper;

    @Autowired
    private NaturalPersonBaseInformationMapper naturalPersonBaseInformationMapper;

    @Autowired
    private EnterpriseBasicInfoMapper enterpriseBasicInfoMapper;

    @Autowired
    private UserBaseInformationMapper userBaseInformationMapper;

    @Autowired
    private UserRoleRelationMapper userRoleRelationMapper;

    @Autowired
    private Mapper dozerBeanMapper;

    @Autowired
    private SystemParametersMapper systemParametersMapper;

    @Autowired
    private IfpRedisson redisson;

    @Autowired
    private InPortRoleMapper inPortRoleMapper;

    @Autowired
    private OrganizationalRoleRelationMapper organizationalRoleRelationMapper;

    @Autowired
    EmployeeInformationMapper employeeInformationMapper;

    @Autowired
    EmployeeInformationHistoryMapper employeeInformationHistoryMapper;

    @Autowired
    UserBaseInformationHistoryMapper userBaseInformationHistoryMapper;

    @Autowired
    NaturalPersonBaseInformationHistoryMapper naturalPersonBaseInformationHistoryMapper;

    @Autowired
    GeneralService generalService;

    @Autowired
    UrEsignMapper urEsignMapper;

    @Autowired
    CertificateManageMapper certificateManageMapper;

    @Autowired
    OrganizationManagementModel organizationManagementModel;

    private QueryWrapper<UserBaseInformation> queryWrapper = null;

    @Autowired
    private CommUtils commUtils;

    @Autowired
    SysDataDicMapper sysDataDicMapper;

    @Autowired
    EnterpriseBasicInfoHistoryMapper enterpriseBasicInfoHistoryMapper;

    @Autowired
    EnterpriseUserInfoHistoryMapper enterpriseUserInfoHistoryMapper;

    @Autowired
    CloudPlatformSyncMapper cloudPlatformSyncMapper;

    @Autowired
    ColdChainModel coldChainModel;

    @Autowired
    AuthorizationbookurlModel authorizationbookurlModel;

    @Autowired
    ColdChainHistoryModel coldChainHistoryModel;

    @Autowired
    AuthorizationbookurlHistoryModel authorizationbookurlHistoryModel;

    // add by gaole.dai 2019-12-31 引入e签宝服务 begin
    @Autowired
    EsignApiModel esignApiModel;
    // add by gaole.dai 2019-12-31 引入e签宝服务 end

    @Autowired
    ZtProducer ztProducer;

    @Autowired
    EnterpriseUserRoleMapper enterpriseUserRoleMapper;

    @Autowired
    EnterpriseEnclosureModel enterpriseEnclosureModel;

    @Autowired
    EnterpriseEnclosureMapper enterpriseEnclosureMapper;

    @Autowired
    EnterpriseEnclosureHistoryModel enterpriseEnclosureHistoryModel;

    @Autowired
    ChannelConfigModel channelConfigModel;

    @Autowired
    private CloudPlatformIdRelationMapper cloudPlatformIdRelationMapper;

    @Autowired
    private CloudPlatformRegionRelationMapper cloudPlatformRegionRelationMapper;

    @Autowired
    private CloudPlatformAsync cloudPlatformAsync;

    @Autowired
    private EsignServiceImpl esignServiceImpl;

    @Autowired
    private OrganizationalStructureMapper organizationalStructureMapper;

    @Autowired
    private FactorsModifyRecordMapper factorsModifyRecordMapper;

    @Autowired
    private UserDeleteRecordMapper userDeleteRecordMapper;

    private static final String queryChannelSplitFlag = ",";

    /* 用户信息修改事务层 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 用户信息修改事务层
     * @author: DaiGaoLe
     * @create: 2019-10-22 09:47
     **/
    @Transactional(rollbackFor = Exception.class)
    public String changeUserInof(ChangeUserInfoReq requestObject) {
        // 声明变量 begin
        // 用户id
        Integer userId = requestObject.getUserId();
        // String userAccounts = requestObject.getUserAccounts();
        Integer operationUserId = requestObject.getOperationUserId();
        // 企业用户信息
        // ChangeUserInfoEnterpriseBasicInfo changeUserInfoEnterpriseBasicInfo =
        // requestObject.getChangeUserInfoEnterpriseBasicInfo();
        // 企业员工用户信息
        ChangeUserInfoEnterpriseUserInfo changeUserInfoEnterpriseUserInfo =
                requestObject.getChangeUserInfoEnterpriseUserInfo();
        // 自然人用户信息
        ChangeUserInfoNaturalPersonBase changeUserInfoNaturalPersonBase =
                requestObject.getChangeUserInfoNaturalPersonBase();
        String returnsResult = SystemConstant.SYSTEM_SUCCESS;
        // 声明变量 end
        UserBaseInformation userBaseInformation = this.getById(userId);
        if (userBaseInformation == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }
        if (SystemConstant.USER_TYPE_3.equals(userBaseInformation.getUserType())) {
            if (CommUtils.objectIsNull(requestObject.getEnterpriseId())) {
                throw new BusinessException("enterpriseId不能为空", ErrorMessageConstant.ECUC0000_CODE);
            }
        }
        // 校验数据
        changeUserInofCheck(requestObject, userBaseInformation, changeUserInfoEnterpriseUserInfo,
                changeUserInfoNaturalPersonBase);

        // add by liwq on 2021-07-06 start
        // 获取数据库里保存的手机号
        String oldPhone = null;
        if (requestObject.getChangeUserInfoEnterpriseUserInfo() != null) {
            EnterpriseUserInfo enterpriseUserInfo = getEnterpriseUserInfo(requestObject.getChannel(),
                    requestObject.getUserId(), requestObject.getEnterpriseId());
            if (enterpriseUserInfo != null) {
                oldPhone = enterpriseUserInfo.getTelephone();
            }
        }

        // 获取数据库里保存的身份证号
        String papersNo = null;
        LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                new LambdaQueryWrapper<NaturalPersonBaseInformation>();
        queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
        NaturalPersonBaseInformation naturalPersonBaseInformation =
                naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
        if (naturalPersonBaseInformation != null) {
            papersNo = naturalPersonBaseInformation.getPapersNo();
        }
        // add by liwq on 2021-07-06 end

        // 更新数据
        changeUserInofUpdate(requestObject, userBaseInformation, changeUserInfoEnterpriseUserInfo,
                changeUserInfoNaturalPersonBase);

        // add by liwq on 2021-07-06 start
        // 将数据同步到云平台
        cloudPlatformAsync.mergeUserDataToCloudPlatform(requestObject, oldPhone, papersNo);
        // add by liwq on 2021-07-06 end

        return returnsResult;
    }

    /**
     * @program: 2019-10-12_userCenter
     * @description: 企业信息修改事务层
     * @author: Songyf
     * @create: 2020-07-21 15:47
     **/
    @Transactional(rollbackFor = Exception.class)
    public String changeBasicInfo(ChangeUserInfoEnterpriseBasicInfo requestObject) {
        Integer userId = requestObject.getUserId();
        String channel = requestObject.getChannel();
        Integer operationUserId = requestObject.getOperationUserId();
        String returnsResult = SystemConstant.SYSTEM_SUCCESS;
        LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
        queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
        EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
        if (enterpriseBasicInfo == null) {
            throw new BusinessException("该企业客户不存在", ErrorMessageConstant.ECUC0002_CODE);
        }

        //add by liwq on 2022-10-12 start
        //修改企业客户时，增加校验逻辑：判断该企业客户是否已锁定，若未锁定，则阻断交易；若已经锁定，则继续判断当前渠道是否与加锁渠道一致，若不一致，阻断交易，若一致，则继续原修改逻辑。
        if (enterpriseBasicInfo != null) {
            //是否锁定0:正常1:锁定
            String isUnLock = enterpriseBasicInfo.getIsUnlock();
            if (!"1".equals(isUnLock)) {
                throw new BusinessException("该企业客户未锁定，禁止修改！", ErrorMessageConstant.ECUC0071_CODE);
            }
            if ("1".equals(isUnLock)) {
                String channelUnlockState = enterpriseBasicInfo.getChannelUnlockState();
                if (!requestObject.getChannel().equals(channelUnlockState)) {
                    throw new BusinessException("当前渠道与加锁渠道不一致，请检查！", ErrorMessageConstant.ECUC0072_CODE);
                }
            }
        }
        //add by liwq on 2022-10-12 end

        String sendName = enterpriseBasicInfo.getCompanyName();
        String companyName = requestObject.getCompanyName();
        String oldPapersNo = enterpriseBasicInfo.getPapersNo();
        String newPapersNo = requestObject.getPapersNo();
        String oldBLNo = enterpriseBasicInfo.getBussinessLicenseNo();
        String newBLNo = requestObject.getBussinessLicenseNo();
        if (StringUtils.isNotBlank(newPapersNo)) {
            if (!newPapersNo.equals(oldPapersNo)) {
                LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI1 = new LambdaQueryWrapper<EnterpriseBasicInfo>();
                queryWrapperEBI1.eq(EnterpriseBasicInfo::getPapersNo, newPapersNo);
                queryWrapperEBI1.ne(EnterpriseBasicInfo::getUserId, userId);
                if (enterpriseBasicInfoMapper.selectCount(queryWrapperEBI1) > 0) {
                    throw new BusinessException("用户(" + newPapersNo + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
                }
            }
        }
        //2022-4-20 新增企业两要素校验
        if (StringUtils.isNotBlank(newPapersNo) || StringUtils.isNotBlank(companyName)) {
            if (requestObject.getParentId() == null) {
                //进行企业两要素校验
                Bureau2FactorsReq req = mapper.map(requestObject, Bureau2FactorsReq.class);
                if (StringUtils.isNotBlank(companyName)) {
                    req.setName(companyName);
                } else {
                    req.setName(enterpriseBasicInfo.getCompanyName());
                }
                if (StringUtils.isNotBlank(requestObject.getPapersType())) {
                    if (SystemConstant.PAPERS_TYPE_00.equals(requestObject.getPapersType())) {
                        if (StringUtils.isNotBlank(newPapersNo)) {
                            req.setOrgCode(newPapersNo);
                        } else {
                            req.setOrgCode(oldPapersNo);
                        }
                    } else {
                        if (StringUtils.isNotBlank(newBLNo)) {
                            req.setOrgCode(newBLNo);
                        } else {
                            req.setOrgCode(oldBLNo);
                        }
                    }
                } else {
                    if (SystemConstant.PAPERS_TYPE_00.equals(enterpriseBasicInfo.getPapersType())) {
                        if (StringUtils.isNotBlank(newPapersNo)) {
                            req.setOrgCode(newPapersNo);
                        } else {
                            req.setOrgCode(oldPapersNo);
                        }
                    } else {
                        if (StringUtils.isNotBlank(newBLNo)) {
                            req.setOrgCode(newBLNo);
                        } else {
                            req.setOrgCode(oldBLNo);
                        }
                    }
                }
                ServiceResult<String> s = esignServiceImpl.bureau2FactorsVerification(req);
                if (StringUtils.isEmpty(s.getResult())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,
                            ErrorMessageConstant.ECUC0038_CODE);
                }
            } else {
                enterpriseBasicInfo.setPapersNo("");
                enterpriseBasicInfo.setPapersType("");
            }
        }
        List<Coldchain> coldchainListHistory = coldChainModel.searchByUserId(userId);
        // if (StringUtils.isNotEmpty(requestObject.getAdminTelephone())
        // && !CommUtils.isPhone(requestObject.getAdminTelephone())) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        // }
        if (StringUtils.isNotEmpty(requestObject.getEmail()) && !CommUtils.isEmail(requestObject.getEmail())) {
            throw new BusinessException("邮箱格式不正确", ErrorMessageConstant.ECUC0016_CODE);
        }
        // if (StringUtils.isNotEmpty(requestObject.getAdminEmail())
        // && !CommUtils.isEmail(requestObject.getAdminEmail())) {
        // throw new BusinessException("管理员邮箱格式不正确", ErrorMessageConstant.ECUC0016_CODE);
        // }
        if (StringUtils.isNotEmpty(companyName)) {
            enterpriseBasicInfo.setUserName(companyName);
            // LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperBI = new LambdaQueryWrapper<>();
            // queryWrapperBI.eq(EnterpriseBasicInfo::getCompanyName, companyName);
            // queryWrapperBI.ne(EnterpriseBasicInfo::getUserId, requestObject.getUserId());
            // Integer integer = enterpriseBasicInfoMapper.selectCount(queryWrapperBI);
            // if (integer > 0) {
            // throw new BusinessException("用户(" + companyName + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
            // }
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperBI1 = new LambdaQueryWrapper<>();
            queryWrapperBI1.eq(EnterpriseBasicInfo::getParentId, requestObject.getUserId());
            List<EnterpriseBasicInfo> ebiLists = enterpriseBasicInfoMapper.selectList(queryWrapperBI1);
            for (int k = 0; k < ebiLists.size(); k++) {
                ebiLists.get(k).setCompanyName(ebiLists.get(k).getCompanyName().replace(sendName, companyName));
                ebiLists.get(k).setUserName(ebiLists.get(k).getCompanyName());
                ebiLists.get(k).setModifiedBy(operationUserId);
                ebiLists.get(k).setGmtModified(LocalDateTime.now());
                LambdaQueryWrapper<EnterpriseBasicInfo> updateWrapper = new LambdaQueryWrapper<>();
                updateWrapper.eq(EnterpriseBasicInfo::getUserId, ebiLists.get(k).getUserId());
                enterpriseBasicInfoMapper.update(ebiLists.get(k), updateWrapper);
            }
        }
        if (enterpriseBasicInfo != null && requestObject != null) {
            // 冷链
            List<Coldchain> coldChainList = new ArrayList<Coldchain>();
            List<ColdchainReq> oldColdChainList = requestObject.getColdChainList();
            coldChainModel.delete(userId);
            if (oldColdChainList != null) {
                Iterator<ColdchainReq> iterator = oldColdChainList.iterator();
                while (iterator.hasNext()) {
                    ColdchainReq chain = iterator.next();
                    Coldchain coldchain = new Coldchain();
                    coldchain.setColdchainUserCode(chain.getColdchainUserCode());
                    coldchain.setColdchainUserName(chain.getColdchainUserName());
                    coldchain.setUserId(userId);
                    coldchain.setCreateBy(operationUserId);
                    coldchain.setGmtCreate(LocalDateTime.now());
                    coldchain.setModifiedBy(operationUserId);
                    coldchain.setGmtModified(LocalDateTime.now());
                    coldchain.setChannel(channel);
                    coldChainList.add(coldchain);
                }
                coldChainModel.saveBatch(coldChainList);
            }
            // 附件
            List<String> channelList = new ArrayList<String>();
            channelList.add(channel);
            if (StringUtils.isNotBlank(enterpriseBasicInfo.getAuthorizedChannels())) {
                channelList
                        .addAll(Arrays.asList(enterpriseBasicInfo.getAuthorizedChannels().split(queryChannelSplitFlag)));
            }
            List<EnterpriseEnclosure> enclosureList = new ArrayList<EnterpriseEnclosure>();
            List<EnterpriseEnclosureReq> oldEnclosureList = requestObject.getEnclosureLists();
            LambdaQueryWrapper<EnterpriseEnclosure> queryWrapperEE = new LambdaQueryWrapper<EnterpriseEnclosure>();
            queryWrapperEE.eq(EnterpriseEnclosure::getUserId, userId);
            queryWrapperEE.in(EnterpriseEnclosure::getChannel, channelList);
            List<EnterpriseEnclosure> enterpriseEnclosureHistory = enterpriseEnclosureMapper.selectList(queryWrapperEE);
            enterpriseEnclosureMapper.delete(queryWrapperEE);
            if (oldEnclosureList != null) {
                Iterator<EnterpriseEnclosureReq> iterator = oldEnclosureList.iterator();
                while (iterator.hasNext()) {
                    EnterpriseEnclosureReq enclosureReq = iterator.next();
                    EnterpriseEnclosure enclosure = new EnterpriseEnclosure();
                    enclosure.setEnclosureType(enclosureReq.getEnclosureType());
                    enclosure.setEnclosureUrl(enclosureReq.getEnclosureUrl());
                    enclosure.setUserId(userId);
                    enclosure.setCreateBy(operationUserId);
                    enclosure.setGmtCreate(LocalDateTime.now());
                    enclosure.setModifiedBy(operationUserId);
                    enclosure.setGmtModified(LocalDateTime.now());
                    enclosure.setChannel(channel);
                    enclosureList.add(enclosure);
                }
                enterpriseEnclosureModel.saveBatch(enclosureList);
            }
            // 法定代表人授权委托书url
            Authorizationbookurl temp =
                    authorizationbookurlModel.searchByUserIdAndChannel(userId, requestObject.getChannel());
            authorizationbookurlModel.delete(userId, requestObject.getChannel());
            if (StringUtils.isNotEmpty(requestObject.getAuthorizationbookurl())) {
                Authorizationbookurl authorizationbookurl = new Authorizationbookurl();
                authorizationbookurl.setAuthorizationBookUrl(requestObject.getAuthorizationbookurl());
                authorizationbookurl.setChannel(requestObject.getChannel());
                authorizationbookurl.setUserId(userId);
                authorizationbookurl.setCreateBy(operationUserId);
                authorizationbookurl.setGmtCreate(LocalDateTime.now());
                authorizationbookurl.setModifiedBy(operationUserId);
                authorizationbookurl.setGmtModified(LocalDateTime.now());
                authorizationbookurlModel.save(authorizationbookurl);
            }
            EnterpriseBasicInfoHistory enterpriseBasicInfoHistory =
                    dozerBeanMapper.map(enterpriseBasicInfo, EnterpriseBasicInfoHistory.class);
            enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
            generalService.updateEnterpriseBasicInfo(requestObject, enterpriseBasicInfo, operationUserId);
            requestObject.setChannel(channel);
            //2022-11-24新增业态相关及四要素修改记录
            if(requestObject.getFormatId()!=null){
                if (StringUtils.isNotBlank(enterpriseBasicInfo.getAuthorizedFormats())&&enterpriseBasicInfo.getAuthorizedFormats().contains(requestObject.getFormatId().toString())) {
                } else {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }
            //四要素修改记录
            FactorsModifyRecord factorsModifyRecord = new FactorsModifyRecord();
            boolean companyfactors = false;
            if(StringUtils.isNotBlank(enterpriseBasicInfo.getCompanyName())&&!enterpriseBasicInfo.getCompanyName().equals(enterpriseBasicInfoHistory.getCompanyName())){
                factorsModifyRecord.setOldUserName(enterpriseBasicInfoHistory.getCompanyName());
                factorsModifyRecord.setNewUserName(enterpriseBasicInfo.getCompanyName());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(enterpriseBasicInfo.getPapersNo())&&!enterpriseBasicInfo.getPapersNo().equals(enterpriseBasicInfoHistory.getPapersNo())){
                factorsModifyRecord.setOldPapersNo(enterpriseBasicInfoHistory.getPapersNo());
                factorsModifyRecord.setNewPapersNo(enterpriseBasicInfo.getPapersNo());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(enterpriseBasicInfo.getLegalRepresentativeName())&&!enterpriseBasicInfo.getLegalRepresentativeName().equals(enterpriseBasicInfoHistory.getLegalRepresentativeName())){
                factorsModifyRecord.setOldLegalRepresentativeName(enterpriseBasicInfoHistory.getLegalRepresentativeName());
                factorsModifyRecord.setNewLegalRepresentativeName(enterpriseBasicInfo.getLegalRepresentativeName());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(enterpriseBasicInfo.getLrnCertificateNo())&&!enterpriseBasicInfo.getLrnCertificateNo().equals(enterpriseBasicInfoHistory.getLrnCertificateNo())){
                factorsModifyRecord.setOldLrnCertificateNo(enterpriseBasicInfoHistory.getLrnCertificateNo());
                factorsModifyRecord.setNewLrnCertificateNo(enterpriseBasicInfo.getLrnCertificateNo());
                companyfactors = true;
            }
            if(companyfactors){
                factorsModifyRecord.setUserId(userId);
                factorsModifyRecord.setUserType(SystemConstant.USER_TYPE_0);
                factorsModifyRecord.setModifyChannel(channel);
                factorsModifyRecord.setModifyFormat(requestObject.getFormatId());
                factorsModifyRecord.setModifyBy(requestObject.getOperationUserId());
                factorsModifyRecord.setGmtModify(LocalDateTime.now());
                factorsModifyRecord.setAuthorizedFormats(enterpriseBasicInfoHistory.getAuthorizedFormats());
                factorsModifyRecordMapper.insert(factorsModifyRecord);
            }
            // 冷链历史 宋一帆
            List<ColdchainHistory> coldchainHistoryList =
                    BeanUtil.mapList(dozerBeanMapper, coldchainListHistory, ColdchainHistory.class);
            for (int i = 0; i < coldchainHistoryList.size(); i++) {
                coldchainHistoryList.get(i).setId(enterpriseBasicInfoHistory.getId());
            }
            coldChainHistoryModel.saveBatch(coldchainHistoryList);
            // 附件历史 宋一帆
            // LambdaQueryWrapper<EnterpriseEnclosure> queryWrapperEEH = new LambdaQueryWrapper<EnterpriseEnclosure>();
            // queryWrapperEEH.eq(EnterpriseEnclosure::getUserId, userId);
            List<EnterpriseEnclosureHistory> enclosureHistoryList =
                    BeanUtil.mapList(dozerBeanMapper, enterpriseEnclosureHistory, EnterpriseEnclosureHistory.class);
            for (int i = 0; i < enclosureHistoryList.size(); i++) {
                enclosureHistoryList.get(i).setId(enterpriseBasicInfoHistory.getId());
            }
            enterpriseEnclosureHistoryModel.saveBatch(enclosureHistoryList);
            // 法定代表人授权委托书url 宋一帆
            if (temp != null) {
                AuthorizationbookurlHistory authorizationbookurlHistory =
                        dozerBeanMapper.map(temp, AuthorizationbookurlHistory.class);
                authorizationbookurlHistory.setId(enterpriseBasicInfoHistory.getId());
                authorizationbookurlHistoryModel.save(authorizationbookurlHistory);
            }
        }
        if (StringUtils.isNotBlank(requestObject.getSgyfId())) {
            UserBaseInformation user = userBaseInformationMapper.selectById(userId);
            user.setSgyfId(requestObject.getSgyfId());
            userBaseInformationMapper.updateById(user);
        }
        // EnterpriseBasicInfo userInfo = enterpriseBasicInfoMapper.selectById(userId);
        if (StringUtils.isNotEmpty(enterpriseBasicInfo.getAuthorizedChannels())) {
            ztProducer.sendMessagesModifyUserIn(userId, sendName);
        }
        cloudPlatformAsync.authenticationToCloudPlatformCheck(requestObject, SystemConstant.USER_TYPE_0, oldPapersNo,
                newPapersNo, userId);
        return returnsResult;
    }

    private void changeUserInofUpdate(ChangeUserInfoReq requestObject, UserBaseInformation userBaseInformation,
                                      ChangeUserInfoEnterpriseUserInfo changeUserInfoEnterpriseUserInfo,
                                      ChangeUserInfoNaturalPersonBase changeUserInfoNaturalPersonBase) {
        Integer userId = requestObject.getUserId();
        // 主表历史记录id
        Integer userHistoryId = null;
        Integer operationUserId = requestObject.getOperationUserId();
        if (userBaseInformation != null) {
            // 获取数据源渠道
            String sourceChannel = userBaseInformation.getChannel();
            userHistoryId = generalService.insertUserBaseInformationHistory(userBaseInformation);
            dozerBeanMapper.map(requestObject, userBaseInformation);
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setModifiedBy(operationUserId);
            userBaseInformation.setChannel(sourceChannel);
            this.saveOrUpdate(userBaseInformation);
        }

        String userType = userBaseInformation.getUserType();

        if (SystemConstant.USER_TYPE_3.equals(userType)) { // 3-企业员工用户
            EnterpriseUserInfo enterpriseUserInfo =
                    getEnterpriseUserInfo(requestObject.getChannel(), userId, requestObject.getEnterpriseId());
            if (enterpriseUserInfo != null) {
                generalService.insertEnterpriseUserInfoHistory(enterpriseUserInfo, userHistoryId);
                generalService.updateEnterpriseUserInfo(requestObject, changeUserInfoEnterpriseUserInfo,
                        enterpriseUserInfo, operationUserId);
            }
        }
        if (SystemConstant.USER_TYPE_2.equals(userType)) { // 2-个人用户
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation naturalPersonBaseInformation =
                    naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);

            //add by liwq on 2022-10-11 start
            //修改自然人前，判断当前渠道是否在授权渠道之内
            if (naturalPersonBaseInformation != null) {
                String authorizedChannels = naturalPersonBaseInformation.getAuthorizedChannels();
                if (!StringUtils.isEmpty(authorizedChannels)) {
                    String authorizedChannelsArray[] = authorizedChannels.split(",");
                    if (authorizedChannelsArray.length > 0) {
                        List list = Arrays.asList(authorizedChannelsArray);
                        if (!list.contains(requestObject.getChannel())) {
                            throw new BusinessException("当前渠道不在授权渠道列表内", ErrorMessageConstant.ECUC0001_CODE);
                        }
                    }
                }
            }
            //add by liwq on 2022-10-11 end

            if (naturalPersonBaseInformation != null) {
                NaturalPersonBaseInformationHistory naturalPersonBaseInformationHistory = dozerBeanMapper.map(naturalPersonBaseInformation, NaturalPersonBaseInformationHistory.class);
                generalService.insertNaturalPersonBaseInformationHistory(naturalPersonBaseInformation, userHistoryId);
                generalService.updateNaturalPersonBaseInformation(requestObject, changeUserInfoNaturalPersonBase,
                        naturalPersonBaseInformation, operationUserId);
                //2022-11-24新增业态相关及四要素修改记录
                if(requestObject.getFormatId()!=null){
                    if (StringUtils.isNotBlank(naturalPersonBaseInformation.getAuthorizedFormats())&&naturalPersonBaseInformation.getAuthorizedFormats().contains(requestObject.getFormatId().toString())) {
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                    }
                }
                //四要素修改记录
                FactorsModifyRecord factorsModifyRecord = new FactorsModifyRecord();
                boolean companyfactors = false;
                if(StringUtils.isNotBlank(naturalPersonBaseInformation.getUserName())&&!naturalPersonBaseInformation.getUserName().equals(naturalPersonBaseInformationHistory.getUserName())){
                    factorsModifyRecord.setOldUserName(naturalPersonBaseInformationHistory.getUserName());
                    factorsModifyRecord.setNewUserName(naturalPersonBaseInformation.getUserName());
                    companyfactors = true;
                }
                if(StringUtils.isNotBlank(naturalPersonBaseInformation.getPapersNo())&&!naturalPersonBaseInformation.getPapersNo().equals(naturalPersonBaseInformationHistory.getPapersNo())){
                    factorsModifyRecord.setOldPapersNo(naturalPersonBaseInformationHistory.getPapersNo());
                    factorsModifyRecord.setNewPapersNo(naturalPersonBaseInformation.getPapersNo());
                    companyfactors = true;
                }
                if(companyfactors){
                    factorsModifyRecord.setUserId(userId);
                    factorsModifyRecord.setUserType(userType);
                    factorsModifyRecord.setModifyChannel(requestObject.getChannel());
                    factorsModifyRecord.setModifyFormat(requestObject.getFormatId());
                    factorsModifyRecord.setModifyBy(requestObject.getOperationUserId());
                    factorsModifyRecord.setGmtModify(LocalDateTime.now());
                    factorsModifyRecord.setAuthorizedFormats(naturalPersonBaseInformationHistory.getAuthorizedFormats());
                    factorsModifyRecordMapper.insert(factorsModifyRecord);
                }
            }
        }
        // if (SystemConstant.USER_TYPE_0.equals(userType)) { // 0-企业用户
        // EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectById(userId);
        // if (enterpriseBasicInfo != null && changeUserInfoEnterpriseBasicInfo != null) {
        // List<Coldchain> coldChainList = new ArrayList<Coldchain>();
        // List<ColdchainReq> oldColdChainList = changeUserInfoEnterpriseBasicInfo.getColdChainList();
        // Iterator<ColdchainReq> iterator = oldColdChainList.iterator();
        // while(iterator.hasNext()) {
        // ColdchainReq chain = iterator.next();
        // Coldchain coldchain = new Coldchain();
        // coldchain.setColdchainUserCode(chain.getColdchainUserCode());
        // coldchain.setColdchainUserName(chain.getColdchainUserName());
        // coldchain.setUserId(userId);
        // coldchain.setCreateBy(operationUserId);
        // coldchain.setGmtCreate(LocalDateTime.now());
        // coldchain.setModifiedBy(operationUserId);
        // coldchain.setGmtModified(LocalDateTime.now());
        // coldChainList.add(coldchain);
        // }
        // coldChainModel.delete(userId);
        // coldChainModel.insertListColdChain(coldChainList);
        // generalService.insertEnterpriseBasicInfoHistory(enterpriseBasicInfo, userHistoryId);
        // generalService.updateEnterpriseBasicInfo(changeUserInfoEnterpriseBasicInfo, enterpriseBasicInfo,
        // operationUserId);
        // }
        // EnterpriseUserInfo enterpriseUserInfo = enterpriseUserInfoMapper.selectById(userId);
        // if (enterpriseUserInfo != null && changeUserInfoEnterpriseUserInfo != null) {
        // generalService.insertEnterpriseUserInfoHistory(enterpriseUserInfo, userHistoryId);
        // generalService.updateEnterpriseUserInfo(changeUserInfoEnterpriseUserInfo, enterpriseUserInfo,
        // operationUserId);
        // }
        // }
    }

    private void changeUserInofCheck(ChangeUserInfoReq requestObject, UserBaseInformation userBaseInformation,
                                     ChangeUserInfoEnterpriseUserInfo changeUserInfoEnterpriseUserInfo,
                                     ChangeUserInfoNaturalPersonBase changeUserInfoNaturalPersonBase) {

        // 注释掉是因为,从用户中心发起判断是否有在途,审批中心永远都会存在在途任务(用户信息修改在途),造成死循环,故放在审批中心,由审批中心判断是否有在途流程,而进行修改用户信息
        // 需要调用审批中心获取用户是否存在（已经开启）任务不能删除
        /*boolean joinUnfinishedProcess = generalService.isJoinUnfinishedProcess(userId, requestObject);
        if (joinUnfinishedProcess) {
            throw new BusinessException("用户存在在途审批任务不能修改");
        }*/

        // String userAccounts = requestObject.getUserAccounts();
        String userType = userBaseInformation.getUserType();
        String userName = requestObject.getUserName();
        String telephone = requestObject.getTelephone();
        String channel = requestObject.getChannel();
        String papersType = requestObject.getPapersType();
        String papersNo = requestObject.getPapersNo();
        Integer userId = requestObject.getUserId();
        // if (StringUtils.isNotEmpty(userAccounts)) {
        // QueryWrapper<UserBaseInformation> queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("user_accounts", userAccounts);
        // Integer integer = this.getBaseMapper().selectCount(queryWrapper);
        //
        // if (integer > 0&&!requestObject.getUserId().equals(this.getOne(queryWrapper).getUserId())) {
        // throw new BusinessException("账号：" + userAccounts + "已经存在", ErrorMessageConstant.ECUC0001_CODE);
        // }
        // }
        if (SystemConstant.USER_TYPE_3.equals(userType)) {
            EnterpriseUserInfo enterpriseUserInfo =
                    getEnterpriseUserInfo(channel, requestObject.getUserId(), requestObject.getEnterpriseId());
            Integer enterpriseId = enterpriseUserInfo.getEntOperatorId();
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperId = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapperId.eq(EnterpriseUserInfo::getUserId, userId);
            queryWrapperId.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            EnterpriseUserInfo enterpriseUserInfoId = enterpriseUserInfoMapper.selectList(queryWrapperId).get(0);
            if (StringUtils.isNotBlank(papersNo)) {
                if (enterpriseUserInfoMapper.selectCount(queryWrapperId) > 1) {
                    if (!papersNo.equals(enterpriseUserInfoId.getPapersNo())) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0060_MESSAGE,
                                ErrorMessageConstant.ECUC0060_CODE);
                    }
                }
            }
            if (StringUtils.isBlank(userName)) {
                userName = enterpriseUserInfoId.getUserName();
            }
            if (StringUtils.isBlank(telephone)) {
                telephone = enterpriseUserInfoId.getTelephone();
            }
            if (StringUtils.isBlank(papersNo)) {
                papersNo = enterpriseUserInfoId.getPapersNo();
            }
            if (StringUtils.isBlank(papersType)) {
                papersType = enterpriseUserInfoId.getPapersType();
            }
            // if (SystemConstant.PAPERS_TYPE_04.equals(papersType)) {
            // PersonsThreeFactorReq personsThreeFactorReq = new PersonsThreeFactorReq();
            // personsThreeFactorReq.setIdNo(papersNo);
            // personsThreeFactorReq.setMobileNo(telephone);
            // personsThreeFactorReq.setName(userName);
            // String s = esignApiModel.personsServiceProviderThreeFactorVerification(personsThreeFactorReq);
            // if (StringUtils.isEmpty(s)) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,
            // ErrorMessageConstant.ECUC0038_CODE);
            // }
            // }
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
            if (StringUtils.isNotEmpty(telephone)) {
                // 验证员工用户名称+手机号+企业id+渠道是否已使用
                queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
                // queryWrapper.eq(EnterpriseUserInfo::getUserName, userName);
                queryWrapper.eq(EnterpriseUserInfo::getTelephone, telephone);
                queryWrapper.ne(EnterpriseUserInfo::getUserId, userId);
                // queryWrapper.eq(EnterpriseUserInfo::getChannel, channel);
                // queryWrapper.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
                queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapper.orderByDesc(EnterpriseUserInfo::getId);
                List<EnterpriseUserInfo> enterpriseUserInfoRepeat = enterpriseUserInfoMapper.selectList(queryWrapper);
                if (enterpriseUserInfoRepeat.size() > 0) {
                    throw new BusinessException("该手机号已被使用", ErrorMessageConstant.ECUC0024_CODE);
                }
            }
            // 验证证件类型+证件号+企业id+渠道是否已使用
            // 身份证号有效性校验
            if (SystemConstant.PAPERS_TYPE_04.equals(papersType) && !CommUtils.isIdNumber(papersNo)) {
                throw new BusinessException("请输入正确的身份证信息！", "BE00001");
            }
            queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapper.eq(EnterpriseUserInfo::getPapersType, papersType);
            queryWrapper.eq(EnterpriseUserInfo::getPapersNo, papersNo);
            queryWrapper.ne(EnterpriseUserInfo::getUserId, userId);
            // queryWrapper.eq(EnterpriseUserInfo::getChannel, channel);
            // queryWrapper.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
            queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            queryWrapper.orderByDesc(EnterpriseUserInfo::getId);
            List<EnterpriseUserInfo> enterpriseUserInfoRepeat1 = enterpriseUserInfoMapper.selectList(queryWrapper);
            if (enterpriseUserInfoRepeat1.size() > 0) {
                throw new BusinessException("该企业员工证件信息已使用，请重新输入！", ErrorMessageConstant.ECUC0001_CODE);
            }
        }
        if (changeUserInfoNaturalPersonBase != null
                && StringUtils.isNotEmpty(changeUserInfoNaturalPersonBase.getSpouseTelephone())
                && !CommUtils.isPhone(changeUserInfoNaturalPersonBase.getSpouseTelephone())) {
            throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }

        // if (changeUserInfoEnterpriseBasicInfo != null &&
        // StringUtils.isNotEmpty(changeUserInfoEnterpriseBasicInfo.getAdminTelephone())
        // && !CommUtils.isPhone(changeUserInfoEnterpriseBasicInfo.getAdminTelephone())) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        // }

        if (SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType())) { // 自然人
            // 若证件类型为身份证则校验，若为其它证件类型则跳过校验
            if (SystemConstant.PAPERS_TYPE_04.equals(requestObject.getPapersType())) {
                if (StringUtils.isNotEmpty(requestObject.getPapersNo())
                        && !CommUtils.isIdNumber(requestObject.getPapersNo())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0016_MESSAGE,
                            ErrorMessageConstant.ECUC0016_CODE);
                }
            }
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapper =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapper.eq(NaturalPersonBaseInformation::getTelephone, telephone);
            NaturalPersonBaseInformation naturalPersonBaseInformation =
                    naturalPersonBaseInformationMapper.selectOne(queryWrapper);
            if (naturalPersonBaseInformation != null && !userId.equals(naturalPersonBaseInformation.getUserId())) {
                throw new BusinessException("该手机号已被使用，请重新输入！", ErrorMessageConstant.ECUC0024_CODE);
            }
            if (StringUtils.isNotBlank(requestObject.getPapersNo())) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNP =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersType, requestObject.getPapersType());
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersNo, requestObject.getPapersNo());
                queryWrapperNP.ne(NaturalPersonBaseInformation::getUserId, userId);
                if (naturalPersonBaseInformationMapper.selectCount(queryWrapperNP) > 0) {
                    throw new BusinessException("用户(" + papersNo + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
                }
            }
            //进行个人两要素校验
            if (StringUtils.isNotBlank(userName) || StringUtils.isNotBlank(papersNo)) {
                ValidPersonBaseReq req = mapper.map(requestObject, ValidPersonBaseReq.class);
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB = new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, requestObject.getUserId());
                NaturalPersonBaseInformation npb = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
                if (StringUtils.isNotBlank(userName)) {
                    req.setName(userName);
                } else {
                    req.setName(npb.getUserName());
                }
                if (StringUtils.isNotBlank(papersNo)) {
                    req.setIdNo(papersNo);
                } else {
                    req.setIdNo(npb.getPapersNo());
                }
                ServiceResult<String> s = esignServiceImpl.individualVerifyBase(req);
                if (StringUtils.isEmpty(s.getResult())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,
                            ErrorMessageConstant.ECUC0038_CODE);
                }
            }
        }

        // if (changeUserInfoNaturalPersonBase != null &&
        // StringUtils.isNotEmpty(changeUserInfoNaturalPersonBase.getSpouseCertificateNo())
        // && !CommUtils.isIdNumber(changeUserInfoNaturalPersonBase.getSpouseCertificateNo())) {
        // throw new BusinessException("配偶证件号码格式不正确", ErrorMessageConstant.ECUC0016_CODE);
        // }

        // if (changeUserInfoEnterpriseBasicInfo != null &&
        // StringUtils.isNotEmpty(changeUserInfoEnterpriseBasicInfo.getEmail())
        // && !CommUtils.isEmail(changeUserInfoEnterpriseBasicInfo.getEmail())) {
        // throw new BusinessException("邮箱格式不正确", ErrorMessageConstant.ECUC0016_CODE);
        // }
        //
        // if (changeUserInfoEnterpriseBasicInfo != null &&
        // StringUtils.isNotEmpty(changeUserInfoEnterpriseBasicInfo.getAdminEmail())
        // && !CommUtils.isEmail(changeUserInfoEnterpriseBasicInfo.getAdminEmail())) {
        // throw new BusinessException("管理员邮箱格式不正确", ErrorMessageConstant.ECUC0016_CODE);
        // }

    }
    /* 用户信息修改事务层 end */

    /* 删除用户 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 删除用户
     * @author: DaiGaoLe
     * @create: 2019-10-22 11:19
     **/
    @Transactional(rollbackFor = Exception.class)
    public String deleteUser(DeleteUserReq requestObject) {
        // 声明变量 begin
        String returnsResult = SystemConstant.SYSTEM_SUCCESS;
        String channel = requestObject.getChannel();
        // 用户id
        Integer userId = requestObject.getUserId();
        Integer enterpriseId = requestObject.getEnterpriseId();
        Integer operationUserId = requestObject.getOperationUserId();
        Integer formatId = requestObject.getFormatId();
        if (userId.equals(operationUserId)) {// 如果相同直接返回
            throw new BusinessException(ErrorMessageConstant.ECUC0003_MESSAGE, ErrorMessageConstant.ECUC0003_CODE);
        }
        UserBaseInformation user = null;
        UserBaseInformation operation = null;
        String userType = null;
        // 用户类型
        String operationuTyp = null;
        // 声明变量 end

        QueryWrapper<UserBaseInformation> queryWrapperUbi = new QueryWrapper<>();
        queryWrapperUbi.eq("user_id", userId);
        user = this.getBaseMapper().selectOne(queryWrapperUbi);

        if (user == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }
        // 需要调用审批中心获取用户是否存在（已经开启）任务不能删除
        boolean joinUnfinishedProcess = generalService.isJoinUnfinishedProcess(userId, requestObject);
        if (joinUnfinishedProcess) {
            throw new BusinessException(ErrorMessageConstant.ECUC0004_MESSAGE, ErrorMessageConstant.ECUC0004_CODE);
        }
        LambdaQueryWrapper<OrganizationalRoleRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrganizationalRoleRelation::getUserId, userId);
        queryWrapper.eq(OrganizationalRoleRelation::getOrganizationalId, enterpriseId);
        queryWrapper.eq(OrganizationalRoleRelation::getChannel, channel);
        Integer integer = organizationalRoleRelationMapper.selectCount(queryWrapper);
        if (integer > 0) {
            throw new BusinessException(ErrorMessageConstant.ECUC0005_MESSAGE, ErrorMessageConstant.ECUC0005_CODE);
        }
        operation = this.getById(operationUserId);
        if (operation == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0006_MESSAGE, ErrorMessageConstant.ECUC0006_CODE);
        }
        userType = user.getUserType();
        if (SystemConstant.USER_TYPE_1.equals(userType)) {
            // 1-港内员工用户 或者 3-企业员工用户 的业务逻辑
            // 港员工和企业员工用户删除就是全不渠道删除
            if (CommUtils.objectIsNull(enterpriseId)) {
                throw new BusinessException("enterpriseId不能为空", ErrorMessageConstant.ECUC0001_CODE);
            }
            LambdaQueryWrapper<EmployeeInformation> queryWrapperEI = new LambdaQueryWrapper<EmployeeInformation>();
            queryWrapperEI.eq(EmployeeInformation::getUserId, userId);
            queryWrapperEI.eq(EmployeeInformation::getOrganizationalId, enterpriseId);
            queryWrapperEI.eq(EmployeeInformation::getChannel, channel);
            queryWrapperEI.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
            EmployeeInformation employeeInformation = employeeInformationMapper.selectOne(queryWrapperEI);
            if (employeeInformation == null) {
                throw new BusinessException("该用户不存在或已被删除", ErrorMessageConstant.ECUC0001_CODE);
            }
            //2022-09-21 syf 新增业态判断
            if (formatId != null) {
                OrganizationalStructure temp = new OrganizationalStructure();
                LambdaQueryWrapper<OrganizationalStructure> queryParent = new LambdaQueryWrapper();
                queryParent.eq(OrganizationalStructure::getOrganizationalId, employeeInformation.getOrganizationalId());
                queryParent.orderByDesc(OrganizationalStructure::getGmtModified);
                List<OrganizationalStructure> orglists = organizationalStructureMapper.selectList(queryParent);
                if (orglists.size() > 0) {
                    temp = orglists.get(0);
                }
                if (temp != null) {
                    temp = organizationManagementModel.selectFormatIdByOrganizational(temp);
                }
                if (!formatId.equals(temp.getOrganizationalId())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }
            // String deleteChannelUsers = employeeInformation.getIsDelete();
            employeeInformation.setIsDelete(SystemConstant.IS_DELETE_1);
            employeeInformation.setGmtModified(LocalDateTime.now());
            employeeInformation.setModifiedBy(operationUserId);
            employeeInformationMapper.update(employeeInformation, queryWrapperEI);
            LambdaQueryWrapper<EmployeeInformation> queryWrapperEID = new LambdaQueryWrapper<EmployeeInformation>();
            queryWrapperEID.eq(EmployeeInformation::getUserId, userId);
            queryWrapperEID.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
            Integer count = employeeInformationMapper.selectCount(queryWrapperEID);
            if (0 == count) {
                user.setIsDelete(SystemConstant.IS_DELETE_1);
            }
            // if (StringUtils.isNotEmpty(deleteChannelUsers)) {
            // throw new BusinessException("用户不能被重复删除", ErrorMessageConstant.ECUC0005_CODE);
            // }
            // QueryWrapper<SysDataDic> queryWrapperDic = new QueryWrapper<>();
            // StringBuilder sb = new StringBuilder();
            //
            // queryWrapperDic.eq("data_type_no", "channel");
            // queryWrapperDic.eq("data_type_name", "渠道");
            // List<SysDataDic> sysDataDics = sysDataDicMapper.selectList(queryWrapperDic);
            // if (sysDataDics != null && sysDataDics.size() == 0) {
            // throw new BusinessException("渠道字典没有配置，请先配置", ErrorMessageConstant.ECUC0000_CODE);
            // }
            // sysDataDics.forEach(obj -> {
            // sb.append(obj.getDataNo() + ",");
            // });
            // user.setDeleteChannelUsers(sb.substring(0, sb.length() - 1));
        } else if (SystemConstant.USER_TYPE_3.equals(userType)) {
            LambdaQueryWrapper<UserRoleRelation> queryWrapperURR = new LambdaQueryWrapper<>();
            queryWrapperURR.eq(UserRoleRelation::getUserId, userId);
            queryWrapperURR.eq(UserRoleRelation::getEnterpriseId, enterpriseId);
            queryWrapperURR.eq(UserRoleRelation::getChannel, channel);
            Integer integerURR = userRoleRelationMapper.selectCount(queryWrapperURR);
            if (integerURR > 0) {
                throw new BusinessException(ErrorMessageConstant.ECUC0005_MESSAGE, ErrorMessageConstant.ECUC0005_CODE);
            }
            if (CommUtils.objectIsNull(enterpriseId)) {
                throw new BusinessException("enterpriseId不能为空", ErrorMessageConstant.ECUC0001_CODE);
            }
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapperEUI.eq(EnterpriseUserInfo::getUserId, userId);
            queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
            queryWrapperEUI.eq(EnterpriseUserInfo::getChannel, channel);
            queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            EnterpriseUserInfo enterpriseUserInfo = enterpriseUserInfoMapper.selectOne(queryWrapperEUI);
            if (enterpriseUserInfo == null) {
                throw new BusinessException("该用户不存在或已被删除", ErrorMessageConstant.ECUC0001_CODE);
            }
            // String deleteChannelUsers = enterpriseUserInfo.getIsDelete();
            enterpriseUserInfo.setIsDelete(SystemConstant.IS_DELETE_1);
            enterpriseUserInfo.setGmtModified(LocalDateTime.now());
            enterpriseUserInfo.setModifiedBy(operationUserId);
            enterpriseUserInfoMapper.update(enterpriseUserInfo, queryWrapperEUI);
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUID = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapperEUID.eq(EnterpriseUserInfo::getUserId, userId);
            queryWrapperEUID.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            Integer count = enterpriseUserInfoMapper.selectCount(queryWrapperEUID);
            if (count == 0) {
                user.setIsDelete(SystemConstant.IS_DELETE_1);
            }
        } else if (SystemConstant.USER_TYPE_0.equals(userType)) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            EnterpriseBasicInfoHistory enterpriseBasicInfoHistory =
                    dozerBeanMapper.map(enterpriseBasicInfo, EnterpriseBasicInfoHistory.class);
            enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
            String deleteChannelUsers = enterpriseBasicInfo.getDeleteChannelUsers();
            if (StringUtils.isEmpty(deleteChannelUsers)) {
                enterpriseBasicInfo.setDeleteChannelUsers(channel);
            } else {
                if (!deleteChannelUsers.contains(channel) && StringUtils.isNotEmpty(deleteChannelUsers)) {
                    enterpriseBasicInfo.setDeleteChannelUsers(deleteChannelUsers + "," + channel);
                }
            }
            //2022-09-21 syf新增业态判断
            if (formatId != null) {
                String formatString = formatId.toString();
                String authorizedFormats = enterpriseBasicInfo.getAuthorizedFormats();
                if (StringUtils.isNotBlank(authorizedFormats)&&authorizedFormats.contains(formatId.toString())) {
                    authorizedFormats = authorizedFormats.replace("," + formatString, "");
                    authorizedFormats = authorizedFormats.replace(formatString + ",", "");
                    authorizedFormats = authorizedFormats.replace(formatString, "");
                    enterpriseBasicInfo.setAuthorizedFormats(authorizedFormats);
                } else {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }else{
                //2022-10-12 syf删除删掉授权渠道
                String authorizedChannels = enterpriseBasicInfo.getAuthorizedChannels();
                if(StringUtils.isNotBlank(authorizedChannels)&&authorizedChannels.contains(channel)){
                    authorizedChannels = authorizedChannels.replace("," + channel, "");
                    authorizedChannels = authorizedChannels.replace(channel + ",", "");
                    authorizedChannels = authorizedChannels.replace(channel, "");
                    enterpriseBasicInfo.setAuthorizedChannels(authorizedChannels);
                }else{
                    throw new BusinessException("只有授权渠道可以删除", ErrorMessageConstant.ECUC0001_CODE);
                }
            }
            enterpriseBasicInfoMapper.update(enterpriseBasicInfo, queryWrapperEBI);
        } else if (SystemConstant.USER_TYPE_2.equals(userType)) {
            Integer userHistoryId = null;
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB = new LambdaQueryWrapper<>();
            queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation naturalPersonBaseInformation =
                    naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
            UserBaseInformationHistory userBaseInformationHistory =
                    dozerBeanMapper.map(user, UserBaseInformationHistory.class);
            userBaseInformationHistoryMapper.insert(userBaseInformationHistory);
            userHistoryId = userBaseInformationHistory.getId();
            NaturalPersonBaseInformationHistory naturalPersonBaseInformationHistory =
                    dozerBeanMapper.map(naturalPersonBaseInformation, NaturalPersonBaseInformationHistory.class);
            naturalPersonBaseInformationHistory.setId(userHistoryId);
            naturalPersonBaseInformationHistoryMapper.insert(naturalPersonBaseInformationHistory);
            String deleteChannelUsers = naturalPersonBaseInformation.getDeleteChannelUsers();
            if (StringUtils.isEmpty(deleteChannelUsers)) {
                naturalPersonBaseInformation.setDeleteChannelUsers(channel);
            } else {
                if (!deleteChannelUsers.contains(channel) && StringUtils.isNotEmpty(deleteChannelUsers)) {
                    naturalPersonBaseInformation.setDeleteChannelUsers(deleteChannelUsers + "," + channel);
                }
            }
            //2022-09-21 syf新增业态判断
            if (formatId != null) {
                String formatString = formatId.toString();
                String authorizedFormats = naturalPersonBaseInformation.getAuthorizedFormats();
                if (StringUtils.isNotBlank(authorizedFormats)&&authorizedFormats.contains(formatId.toString())) {
                    authorizedFormats = authorizedFormats.replace("," + formatString, "");
                    authorizedFormats = authorizedFormats.replace(formatString + ",", "");
                    authorizedFormats = authorizedFormats.replace(formatString, "");
                    naturalPersonBaseInformation.setAuthorizedFormats(authorizedFormats);
                } else {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }else{
                //2022-10-12 syf删除删掉授权渠道
                String authorizedChannels = naturalPersonBaseInformation.getAuthorizedChannels();
                if(StringUtils.isNotBlank(authorizedChannels)&&authorizedChannels.contains(channel)){
                    authorizedChannels = authorizedChannels.replace("," + channel, "");
                    authorizedChannels = authorizedChannels.replace(channel + ",", "");
                    authorizedChannels = authorizedChannels.replace(channel, "");
                    naturalPersonBaseInformation.setAuthorizedChannels(authorizedChannels);
                }else{
                    throw new BusinessException("只有授权渠道可以删除", ErrorMessageConstant.ECUC0001_CODE);
                }
            }
            naturalPersonBaseInformationMapper.update(naturalPersonBaseInformation, queryWrapperNPB);
        }
        user.setGmtModified(LocalDateTime.now());
        user.setModifiedBy(operationUserId);
        this.saveOrUpdate(user);
        UserDeleteRecord userDeleteRecord = dozerBeanMapper.map(requestObject, UserDeleteRecord.class);
        userDeleteRecord.setUserType(userType);
        userDeleteRecord.setCreateBy(operationUserId);
        userDeleteRecord.setGmtCreate(LocalDateTime.now());
        userDeleteRecordMapper.insert(userDeleteRecord);
        return returnsResult;
    }
    /* 删除用户 end */

    /* 获取邀请码 begin */

    /**
     * @author DaiGaoLe
     * @category 获取邀请吗
     */
    @Transactional(rollbackFor = Exception.class)
    public String getInvitationCode(InvitationCodeReq requestObject) throws Exception {
        // Add By Liwq On 2020-11-25 Start
        // 跨渠道注册 校验上传的可用渠道字段，是否包含 中文逗号等不合规符号；
        Boolean channelFlag = CommUtils.checkChannel(requestObject.getAvailableChannel());
        if (!channelFlag) {
            throw new BusinessException(ErrorMessageConstant.ECUC0050_MESSAGE, ErrorMessageConstant.ECUC0050_CODE);
        }
        // Add By Liwq On 2020-11-25 End
        // 2021-06-30 syf 增加可邀请自然人
        String userType = "0";
        if (StringUtils.isBlank(requestObject.getUserType())) {
            userType = "0";
        } else {
            userType = requestObject.getUserType();
        }
        // 声明变量 begin
        // 生成邀请码
        String invitationCode = null;
        Integer userId = requestObject.getUserId();
        String channel = requestObject.getChannel();
        Map<String, Object> map = new HashMap<>();
        // 从配置表取出的 失效时间会存放在这，单位：天
        String loseEfficacyString = null;
        Integer loseEfficacySeconds = null;

        if (StringUtils.isNotEmpty(requestObject.getContactPhone())
                && !CommUtils.isPhone(requestObject.getContactPhone())) {
            throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }

        if (StringUtils.isNotEmpty(requestObject.getOppositeContactPhone())
                && !CommUtils.isPhone(requestObject.getOppositeContactPhone())) {
            throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }

        // 必须是这个顺序不然就在Redis里面的key不一致了
        // 被邀请客户信息-企业名称不能为空
        String oppositeName = requestObject.getOppositeName();
        // 被邀请客户信息-联系人不能为空
        String oppositeContactPerson = requestObject.getOppositeContactPerson();
        // 被邀请客户信息-联系人手机号不能为空
        String oppositeContactPhone = requestObject.getOppositeContactPhone();
        // 被邀请客户信息-证件号
        String oppositePapersNo = requestObject.getOppositePapersNo();
        String id = "";
        if (SystemConstant.USER_TYPE_2.equals(userType)) {
            if (StringUtils.isBlank(oppositePapersNo)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0062_MESSAGE, ErrorMessageConstant.ECUC0062_CODE);
            }
            id = oppositePapersNo + oppositeContactPerson + oppositeContactPhone + userId;
        } else {
            if (StringUtils.isBlank(oppositeName)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0063_MESSAGE, ErrorMessageConstant.ECUC0063_CODE);
            }
            if (StringUtils.isBlank(requestObject.getEnterpriseName())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0048_MESSAGE, ErrorMessageConstant.ECUC0048_CODE);
            }
            id = oppositeName + oppositeContactPerson + oppositeContactPhone + userId;
        }
        String redisKey = CommUtils.getRedisKey("uubi", "inviteCode", id);
        // 声明变量 end

        QueryWrapper<SystemParameters> queryWrapperSp = new QueryWrapper<>();
        queryWrapperSp.eq("code", "0000000001");
        queryWrapperSp.eq("name", "loseEfficacyTime");
        SystemParameters systemParameters = systemParametersMapper.selectOne(queryWrapperSp);
        if (systemParameters == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0052_MESSAGE, ErrorMessageConstant.ECUC0052_MESSAGE);
        }
        loseEfficacyString = systemParameters.getValue();
        loseEfficacySeconds = Integer.valueOf(loseEfficacyString) * 24 * 60 * 60;
        // 申请静态邀请码 2020-08-03 宋一帆修改
        if (SystemConstant.INVITE_CODE_TYPE_0.equals(requestObject.getInviteCodeType())) {
            // 如果不存在那么就代表用户第一次获取邀请码或者邀请码失效
            if (StringUtils.isEmpty((String) redisson.get(redisKey))) {
                try {
                    UserBaseInformation userBaseInformation = userBaseInformationMapper.selectById(userId);
                    if (userBaseInformation == null) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE,
                                ErrorMessageConstant.ECUC0002_CODE);
                    }
                    if (StringUtils.isEmpty(userBaseInformation.getInviteCode())) {// 首次获取邀请码
                        // 获取邀请码
                        // invitationCode = CommUtils.getInviteCode();
                        invitationCode = getInvitationCodeString();
                        // 保证邀请码
                        userBaseInformation.setInviteCode(invitationCode);
                        // 更新邀请码
                        userBaseInformationMapper.updateById(userBaseInformation);
                        // 保存被要邀请人信息
                        inseterInviteeInformatio(requestObject, invitationCode, loseEfficacyString);
                    } else {// 获取过邀请码
                        invitationCode = userBaseInformation.getInviteCode();
                        QueryWrapper<InviteeInformation> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("user_id", userId);
                        // 2021-6-30 增加可邀请自然人
                        if (SystemConstant.USER_TYPE_2.equals(userType)) {
                            queryWrapper.eq("papers_no", oppositeName);
                        } else {
                            queryWrapper.eq("enterprise_name", oppositeName);
                        }
                        queryWrapper.eq("contacts", oppositeContactPerson);
                        queryWrapper.eq("contacts_telephone", oppositeContactPhone);
                        queryWrapper.eq("invite_code", invitationCode);
                        // queryWrapper.eq("channel", channel);
                        queryWrapper.eq("invite_code_type", SystemConstant.INVITE_CODE_TYPE_0);
                        InviteeInformation inviteeInformation = inviteeInformationMapper.selectOne(queryWrapper);

                        if (inviteeInformation != null) {// 已经存在被邀请人信息了
                            // InviteeInformation inviteeInformation = inviteeInformations.get(0);
                            inviteeInformation.setModifiedBy(requestObject.getOperationUserId());
                            inviteeInformation.setGmtModified(LocalDateTime.now());
                            updateInseterInviteeInformatio(inviteeInformation, requestObject, loseEfficacyString);
                        } else {// 不存在被邀请人信息
                            inseterInviteeInformatio(requestObject, invitationCode, loseEfficacyString);
                        }
                    }
                } catch (Exception e) {
                    throw e;
                }
                redisson.set(redisKey, invitationCode, loseEfficacySeconds);
            } else {
                // 已经存在了邀请码，并在在有效期内,直接从Redis取出并返回。
                invitationCode = redisson.get(redisKey);
            }
        } else {
            UserBaseInformation userBaseInformation = userBaseInformationMapper.selectById(userId);
            if (userBaseInformation == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            if (StringUtils.isEmpty((String) redisson.get(redisKey))) {
                QueryWrapper<InviteeInformation> queryWrapper = new QueryWrapper<>();
                // 2021-6-30 增加可邀请自然人
                if (SystemConstant.USER_TYPE_2.equals(userType)) {
                    queryWrapper.eq("papers_no", oppositeName);
                } else {
                    queryWrapper.eq("enterprise_name", oppositeName);
                }
                queryWrapper.eq("user_id", userId);
                queryWrapper.eq("contacts", oppositeContactPerson);
                queryWrapper.eq("contacts_telephone", oppositeContactPhone);
                // queryWrapper.eq("channel", channel);
                // queryWrapper.eq("state", SystemConstant.UR_INVITEE_INFORMATION_STATE_0);
                queryWrapper.eq("invite_code_type", SystemConstant.INVITE_CODE_TYPE_1);
                InviteeInformation inviteeInformation = inviteeInformationMapper.selectOne(queryWrapper);
                if (inviteeInformation != null) {// 已经存在被邀请人信息了
                    inviteeInformation.setModifiedBy(requestObject.getOperationUserId());
                    inviteeInformation.setGmtModified(LocalDateTime.now());
                    updateInseterInviteeInformatio(inviteeInformation, requestObject, loseEfficacyString);
                    invitationCode = inviteeInformation.getInviteCode();
                } else {// 不存在被邀请人信息
                    // invitationCode = CommUtils.getInviteCode();
                    invitationCode = getUniqueInvitationCodeString();
                    inseterInviteeInformatio(requestObject, invitationCode, loseEfficacyString);
                }
                redisson.set(redisKey, invitationCode, loseEfficacySeconds);
            } else {
                invitationCode = redisson.get(redisKey);
            }
        }
        return invitationCode;
    }

    private void inseterInviteeInformatio(InvitationCodeReq requestObject, String invitationCode,
                                          String loseEfficacyString) throws Exception {
        try {
            // 新增被邀请人信息
            InviteeInformation entity = new InviteeInformation();
            // entity.setId(0);
            entity.setUserId(requestObject.getUserId());
            entity.setInviteCode(invitationCode);
            entity.setEnterpriseName(requestObject.getOppositeName());
            entity.setContacts(requestObject.getOppositeContactPerson());
            entity.setContactsTelephone(requestObject.getOppositeContactPhone());
            entity.setState(SystemConstant.UR_INVITEE_INFORMATION_STATE_0);
            entity.setStartTime(LocalDateTime.now());
            entity.setUserType(requestObject.getUserType());
            entity.setPapersNo(requestObject.getOppositePapersNo());
            // entity.setEndTime(LocalDateTime.now());
            entity.setEndTime(CommUtils.addDateDay(entity.getStartTime(), loseEfficacyString));
            entity.setChannel(requestObject.getChannel());
            entity.setGmtCreate(LocalDateTime.now());
            entity.setCreateBy(requestObject.getOperationUserId());
            entity.setGmtModified(LocalDateTime.now());
            entity.setModifiedBy(requestObject.getOperationUserId());
            entity.setInviteCodeType(requestObject.getInviteCodeType());
            // 可用渠道，解决跨渠道邀请注册；
            entity.setAvailableChannel(requestObject.getAvailableChannel());
            inviteeInformationMapper.insert(entity);
        } catch (Exception e) {
            throw e;
        }

    }

    private void updateInseterInviteeInformatio(InviteeInformation inviteeInformation, InvitationCodeReq requestObject,
                                                String loseEfficacyString) {
        // 更新被邀请人信息
        // InviteeInformation entity = new InviteeInformation();
        // entity.setId(0);
        inviteeInformation.setUserId(requestObject.getUserId());
        // 生效状态
        inviteeInformation.setState(SystemConstant.UR_INVITEE_INFORMATION_STATE_0);
        inviteeInformation.setStartTime(LocalDateTime.now());
        // loseEfficacyString;
        inviteeInformation.setEndTime(CommUtils.addDateDay(inviteeInformation.getStartTime(), loseEfficacyString));
        inviteeInformation.setGmtModified(LocalDateTime.now());
        inviteeInformation.setModifiedBy(requestObject.getOperationUserId());
        // 跨渠道邀请，更新可用渠道
        String nowAvailableChannel = null;// 最新的适用于渠道
        String oriAvailableChannel = inviteeInformation.getAvailableChannel();// 目前数据库表里存的 适用于渠道
        if (StringUtils.isEmpty(oriAvailableChannel)) {
            nowAvailableChannel = requestObject.getAvailableChannel();
        }
        if (!StringUtils.isEmpty(oriAvailableChannel)) {
            nowAvailableChannel = oriAvailableChannel + "," + requestObject.getAvailableChannel();
        }
        inviteeInformation.setAvailableChannel(nowAvailableChannel);
        inviteeInformationMapper.updateById(inviteeInformation);
    }
    /* 获取邀请码 end */

    /* 验证密码登录 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 登录验密事务层
     * @author: DaiGaoLe
     * @create: 2019-10-22 20:36
     **/
    public Integer loginVerification(LoginVerificationReq requestObject) {
        // 声明变量 begin
        Integer userId = null;
        // 验密方式
        String operationType = requestObject.getOperationType();
        // 用户类型
        String userType = requestObject.getUserType();
        // 渠道标识
        String channel = requestObject.getChannel();
        // 手机号
        String telephone = requestObject.getTelephone();
        // 登陆密码
        String loginPassword = requestObject.getLoginPassword();
        // 员工编号
        String employeeNo = requestObject.getEmployeeNo();
        // 用户账号
        String userAccounts = requestObject.getUserAccounts();
        // 用户名称
        String userName = requestObject.getUserName();
        // 所在企业
        Integer enterpriseId = requestObject.getEnterpriseId();
        // 查询条件
        QueryWrapper<UserBaseInformation> queryWrapper = new QueryWrapper<>();
        // 用户信息主表
        UserBaseInformation user = null;
        // 企业用户信息表
        EnterpriseBasicInfo enterpriseBasicInfo = null;
        // 企业员工信息表
        EnterpriseUserInfo enterpriseUserInfo = null;
        List<EnterpriseUserInfo> enterpriseUserInfos = new ArrayList<EnterpriseUserInfo>();
        // 港内员工信息表
        EmployeeInformation employeeInformation = null;
        List<EmployeeInformation> employeeInformations = new ArrayList<EmployeeInformation>();
        // 自然人用户信息表
        NaturalPersonBaseInformation naturalPersonBaseInformation = null;
        // md5加密过后的字符串
        String md5SaltPassword = null;
        // 声明变量 end

        // 0 - 密码登录,1 - 手机号登录,2 - 员工工号登录,3 - 手机号密码登录
        if (SystemConstant.LOGIN_VERIFICATION_TYPE_0.equals(operationType)) {// 0 - 密码登录
            if (StringUtils.isEmpty(loginPassword) || StringUtils.isEmpty(userAccounts)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0007_MESSAGE, ErrorMessageConstant.ECUC0007_CODE);
            }
            queryWrapper.eq("user_accounts", userAccounts);
            queryWrapper.eq("is_delete", SystemConstant.IS_DELETE_0);
            user = this.getOne(queryWrapper);
            if (user == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
            if (user.getUserPassword().equals(md5SaltPassword)) {
                return user.getUserId();
            } else {
                throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE, ErrorMessageConstant.ECUC0008_CODE);
            }
            //
        } else if (SystemConstant.LOGIN_VERIFICATION_TYPE_1.equals(operationType)) {// 1 - 手机号登录
            /*verificationCode*/
            String verificationCode = requestObject.getVerificationCode();
            String importVerificationCode = requestObject.getImportVerificationCode();
            if (!StringUtils.isNotEmpty(verificationCode)) {
                /* 系统生成验证码 */
                throw new BusinessException(ErrorMessageConstant.ECUC0009_MESSAGE, ErrorMessageConstant.ECUC0009_CODE);
            }

            if (importVerificationCode == null) {
                /* 用户输入验证码 */
                throw new BusinessException(ErrorMessageConstant.ECUC0010_MESSAGE, ErrorMessageConstant.ECUC0010_CODE);
            }
            // 验证短信验证码是否一致
            if (!verificationCode.equals(importVerificationCode)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0011_MESSAGE, ErrorMessageConstant.ECUC0011_CODE);
            }

            if (telephone == null || !CommUtils.isPhone(telephone)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
            }

            // queryWrapper.eq("telephone", telephone);
            // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 start
            // queryWrapper.eq("channel", channel);
            // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 end
            if (userType == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0012_MESSAGE, ErrorMessageConstant.ECUC0012_CODE);
            }
            // if (userName == null) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0013_MESSAGE, ErrorMessageConstant.ECUC0013_CODE);
            // }
            // queryWrapper.eq("user_type", userType);
            // if (userType.equals(SystemConstant.USER_TYPE_0)) {
            // LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            // queryWrapperEBI.eq(EnterpriseBasicInfo::getTelephone, telephone);
            // queryWrapperEBI.eq(EnterpriseBasicInfo::getUserName, userName);
            // enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            // if (enterpriseBasicInfo == null) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE,
            // ErrorMessageConstant.ECUC0002_CODE);
            // } else {
            // return enterpriseBasicInfo.getUserId();
            // }
            // }
            if (userType.equals(SystemConstant.USER_TYPE_1)) {
                LambdaQueryWrapper<EmployeeInformation> queryWrapperEI = new LambdaQueryWrapper<EmployeeInformation>();
                queryWrapperEI.eq(EmployeeInformation::getTelephone, telephone);
                // queryWrapperEI.eq(EmployeeInformation::getUserName, userName);
                queryWrapperEI.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEI.orderByDesc(EmployeeInformation::getId);
                employeeInformations = employeeInformationMapper.selectList(queryWrapperEI);
                if (employeeInformations.size() == 0) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    return employeeInformations.get(0).getUserId();
                }
            } else if (userType.equals(SystemConstant.USER_TYPE_2)) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNPB.eq(NaturalPersonBaseInformation::getTelephone, telephone);
                // queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserName, userName);
                naturalPersonBaseInformation = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
                if (naturalPersonBaseInformation == null) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    return naturalPersonBaseInformation.getUserId();
                }
            } else if (userType.equals(SystemConstant.USER_TYPE_3)) {
                if (CommUtils.objectIsNull(enterpriseId)) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0074_MESSAGE, ErrorMessageConstant.ECUC0074_CODE);
                }
                LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
                queryWrapperEUI.eq(EnterpriseUserInfo::getTelephone, telephone);
                // queryWrapperEUI.eq(EnterpriseUserInfo::getUserName, userName);
                queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
                // queryWrapperEUI.eq(EnterpriseUserInfo::getChannel, channel);
                queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getId);
                enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
                if (enterpriseUserInfos.size() == 0) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    return enterpriseUserInfos.get(0).getUserId();
                }
            }

            // queryWrapper.eq("user_name", userName);
            // user = this.getOne(queryWrapper);
            // if (user == null) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            // } else {
            // return user.getUserId();
            // }
        } else if (SystemConstant.LOGIN_VERIFICATION_TYPE_2.equals(operationType)) {// 2 - 员工工号登录
            if (StringUtils.isEmpty(employeeNo)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0014_MESSAGE, ErrorMessageConstant.ECUC0014_CODE);
            }
            if (StringUtils.isEmpty(loginPassword)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0007_MESSAGE, ErrorMessageConstant.ECUC0007_CODE);
            }
            QueryWrapper<EmployeeInformation> queryWrapperEi = new QueryWrapper<>();
            // queryWrapperEi.eq("channel", channel);
            queryWrapperEi.eq("employee_no", employeeNo);
            queryWrapperEi.eq("is_delete", SystemConstant.IS_DELETE_0);
            employeeInformations = employeeInformationMapper.selectList(queryWrapperEi);
            if (employeeInformations.size() == 0) {
                throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE, ErrorMessageConstant.ECUC0015_CODE);
            }
            user = this.baseMapper.selectById(employeeInformations.get(0).getUserId());
            if (user == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
            if (user.getUserPassword().equals(md5SaltPassword)) {
                return user.getUserId();
            } else {
                throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE, ErrorMessageConstant.ECUC0008_CODE);
            }
        } else if (SystemConstant.LOGIN_VERIFICATION_TYPE_3.equals(operationType)) {
            // 3 - 手机号密码登录
            if (telephone == null || !CommUtils.isPhone(telephone)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
            }
            if (StringUtils.isEmpty(loginPassword)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0007_MESSAGE, ErrorMessageConstant.ECUC0007_CODE);
            }
            // queryWrapper.eq("telephone", telephone);
            // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 start
            // queryWrapper.eq("channel", channel);
            // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 end
            if (StringUtils.isEmpty(userType)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0012_MESSAGE, ErrorMessageConstant.ECUC0012_CODE);
            }
            // queryWrapper.eq("user_type", userType);
            // if (StringUtils.isEmpty(userName)) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0013_MESSAGE, ErrorMessageConstant.ECUC0013_CODE);
            // }
            // if (userType.equals(SystemConstant.USER_TYPE_0)) {
            // LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            // queryWrapperEBI.eq(EnterpriseBasicInfo::getTelephone, telephone);
            //// queryWrapperEBI.eq(EnterpriseBasicInfo::getUserName, userName);
            // enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            // if (enterpriseBasicInfo == null) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE,
            // ErrorMessageConstant.ECUC0002_CODE);
            // } else {
            // return enterpriseBasicInfo.getUserId();
            // }
            // } else
            if (userType.equals(SystemConstant.USER_TYPE_1)) {
                LambdaQueryWrapper<EmployeeInformation> queryWrapperEI = new LambdaQueryWrapper<EmployeeInformation>();
                queryWrapperEI.eq(EmployeeInformation::getTelephone, telephone);
                // queryWrapperEI.eq(EmployeeInformation::getUserName, userName);
                queryWrapperEI.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEI.orderByDesc(EmployeeInformation::getId);
                employeeInformations = employeeInformationMapper.selectList(queryWrapperEI);
                if (employeeInformations.size() == 0) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    user = this.baseMapper.selectById(employeeInformations.get(0).getUserId());
                    md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
                    if (user.getUserPassword().equals(md5SaltPassword)) {
                        return user.getUserId();
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                                ErrorMessageConstant.ECUC0008_CODE);
                    }
                }
            } else if (userType.equals(SystemConstant.USER_TYPE_2)) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNPB.eq(NaturalPersonBaseInformation::getTelephone, telephone);
                // queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserName, userName);
                naturalPersonBaseInformation = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
                if (naturalPersonBaseInformation == null) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    user = this.baseMapper.selectById(naturalPersonBaseInformation.getUserId());
                    md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
                    if (user.getUserPassword().equals(md5SaltPassword)) {
                        return user.getUserId();
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                                ErrorMessageConstant.ECUC0008_CODE);
                    }
                }
            } else if (userType.equals(SystemConstant.USER_TYPE_3)) {
                if (CommUtils.objectIsNull(enterpriseId)) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0074_MESSAGE, ErrorMessageConstant.ECUC0074_CODE);
                }
                LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
                queryWrapperEUI.eq(EnterpriseUserInfo::getTelephone, telephone);
                // queryWrapperEUI.eq(EnterpriseUserInfo::getUserName, userName);
                queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
                // queryWrapperEUI.eq(EnterpriseUserInfo::getChannel, channel);
                queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getId);
                enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
                if (enterpriseUserInfos.size() == 0) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                            ErrorMessageConstant.ECUC0002_CODE);
                } else {
                    user = this.baseMapper.selectById(enterpriseUserInfos.get(0).getUserId());
                    md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
                    if (user.getUserPassword().equals(md5SaltPassword)) {
                        return user.getUserId();
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0073_MESSAGE,
                                ErrorMessageConstant.ECUC0008_CODE);
                    }
                }
            }
        } else {
            throw new BusinessException(ErrorMessageConstant.ECUC0036_MESSAGE, ErrorMessageConstant.ECUC0036_CODE);
        }
        // queryWrapper.eq("user_name", userName);
        // user = this.getOne(queryWrapper);
        // if (user == null) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        // }
        // md5SaltPassword = CommUtils.getMd5SaltPassword(loginPassword, user.getSalt());
        // if (user.getUserPassword().equals(md5SaltPassword)) {
        // return user.getUserId();
        // } else {
        // throw new BusinessException(ErrorMessageConstant.ECUC0008_MESSAGE, ErrorMessageConstant.ECUC0008_CODE);
        // }
        // else {
        // throw new BusinessException(ErrorMessageConstant.ECUC0036_MESSAGE,ErrorMessageConstant.ECUC0036_CODE);
        // }
        return userId;
    }
    /* 验证密码登录 end */

    /* 获取用户信息 begin*/

    /**
     * @program: 2019-10-12_userCenter
     * @description: 用户信息
     * @author: DaiGaoLe
     * @create: 2019-10-21 18:38
     **/
    public List<UserInfoDto> queryUserInfo(QueryUserInfoReq requestObject) {
        // 声明变量 begin
        // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 start
        // String channelQuery = requestObject.getChannelQuery();
        // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 end
        IPage<UserBaseInformation> page = null;
        List<UserBaseInformation> records = null;
        ArrayList<UserInfoDto> userInfoDtoList = new ArrayList<>();
        PagerInfo pagerInfo = requestObject.getPagerInfo();
        //2022-09-20 syf校验渠道上传的业态id是否存在
//        if(requestObject.getFormatId()!=null){
//            if(!organizationManagementModel.checkFormatId(requestObject.getFormatId(),requestObject.getChannel())){
//                throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
//            }
//        }
        Page<UserBaseInformation> userBaseInformationPage = new Page<>(pagerInfo.getPageNum(), pagerInfo.getPageSize());
        // 声明变量 end
        // QueryWrapper queryWrapper = new QueryWrapper<>();
        //
        // if (requestObject.getUserId() != null) {
        // queryWrapper.eq("user_id", requestObject.getUserId().intValue());
        // }
        //
        // if (StringUtils.isNotEmpty(requestObject.getUserAccounts())) {
        // queryWrapper.like("user_accounts", requestObject.getUserAccounts());
        // }
        // if (StringUtils.isNotEmpty(requestObject.getSgyfId())) {
        // queryWrapper.eq("sgyf_id", requestObject.getSgyfId());
        // }
        // if (StringUtils.isNotEmpty(requestObject.getDingtalkUserid())) {
        // queryWrapper.eq("dingtalk_userid", requestObject.getDingtalkUserid());
        // }
        //
        // queryWrapper.eq("is_delete", SystemConstant.IS_DELETE_0);
        // queryWrapper.orderByDesc("user_id");
        // ------------------以上为2021/06/03注释

        // queryWrapper.notIn("user_type", SystemConstant.USER_TYPE_1);
        //
        // if (StringUtils.isNotEmpty(requestObject.getUserName())) {
        // queryWrapper.like("user_name", requestObject.getUserName());
        // }
        //
        // if (StringUtils.isNotEmpty(requestObject.getPapersType())) {
        // queryWrapper.like("papers_type", requestObject.getPapersType());
        // }
        //
        // if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
        // queryWrapper.like("papers_no", requestObject.getPapersNo());
        // }
        //
        // //2020-07-30 宋一帆 新增非三证合一条件
        // if (StringUtils.isNotEmpty(requestObject.getBussinessLicenseNo())) {
        // queryWrapper.like("bussiness_license_no", requestObject.getBussinessLicenseNo());
        // }
        //
        // if (StringUtils.isNotEmpty(requestObject.getTaxRegistrationNo())) {
        // queryWrapper.like("tax_registration_no", requestObject.getTaxRegistrationNo());
        // }
        //
        // // 根据手机号查询接口添加 by yangbh in 20200708 start
        // if (StringUtils.isNotEmpty(requestObject.getUserMobile())) {
        // queryWrapper.like("telephone", requestObject.getUserMobile());
        // }
        // 根据手机号查询接口添加 by yangbh in 20200708 end
        // 跨渠道访问控制交由内管配置,不由渠道自行选择 by yangbh in 20200707 start
        /*if (StringUtils.isNotEmpty(channelQuery)) {
            queryWrapper.like("channel", channelQuery);
        }*/
        // 跨渠道访问交由内管控制 不由渠道端自行控制 by yangbh in 20200707 end

        // IPage<UserBaseInformation> page = this.page(userBaseInformationPage, queryWrapper);
        // records = page.getRecords();
        page = userBaseInformationMapper.getUserInfo(userBaseInformationPage, requestObject);
        records = page.getRecords();
        if (records != null && records.size() == 0) {
            // throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            return userInfoDtoList;
        }
        for (UserBaseInformation obj : records) {
            UserInfoDto returnUserInfoDto = new UserInfoDto();
            //
            UserBaseInformationDto userBaseInformationDto = null;

            EnterpriseBasicInfoDto enterpriseBasicInfoDto = null;

            NaturalPersonBaseInformationDto naturalPersonBaseInformationDto = null;

            EnterpriseUserInfoDto enterpriseUserInfoDto = null;

            //
            // userBaseInformationDto = dozerBeanMapper.map(obj, UserBaseInformationDto.class);
            // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
            if (SystemConstant.USER_TYPE_0.equals(obj.getUserType())) {
                List<EnterpriseUserInfoDto> enterpriseUserInfoDtos = new ArrayList<EnterpriseUserInfoDto>();
                LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
                queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, obj.getUserId());
                // queryWrapperEBI.orderByDesc(EnterpriseBasicInfo::getGmtCreate);
                // if (StringUtils.isNotEmpty(requestObject.getUserMobile())) {
                // queryWrapperEBI.like(EnterpriseBasicInfo::getTelephone, requestObject.getUserMobile());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getPapersType())) {
                // queryWrapperEBI.eq(EnterpriseBasicInfo::getPapersType, requestObject.getPapersType());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
                // queryWrapperEBI.eq(EnterpriseBasicInfo::getPapersNo, requestObject.getPapersNo());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getBussinessLicenseNo())) {
                // queryWrapperEBI.eq(EnterpriseBasicInfo::getBussinessLicenseNo,
                // requestObject.getBussinessLicenseNo());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getTaxRegistrationNo())) {
                // queryWrapperEBI.eq(EnterpriseBasicInfo::getTaxRegistrationNo,
                // requestObject.getTaxRegistrationNo());
                // }
                // if (!CommUtils.objectIsNull(requestObject.getParentId())) {
                // queryWrapperEBI.eq(EnterpriseBasicInfo::getParentId, requestObject.getParentId());
                // }
                queryWrapperEBI.orderByDesc(EnterpriseBasicInfo::getUserId);
                EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
                if (enterpriseBasicInfo != null) {
                    LambdaQueryWrapper<EnterpriseEnclosure> queryEE = new LambdaQueryWrapper<EnterpriseEnclosure>();
                    queryEE.eq(EnterpriseEnclosure::getUserId, enterpriseBasicInfo.getUserId());
                    userBaseInformationDto = dozerBeanMapper.map(enterpriseBasicInfo, UserBaseInformationDto.class);
                    userBaseInformationDto.setUserAccounts(obj.getUserAccounts());
                    userBaseInformationDto.setSgyfId(obj.getSgyfId());
                    userBaseInformationDto.setUserType(obj.getUserType());
                    userBaseInformationDto.setBusinessSeqNo(obj.getBusinessSeqNo());
                    userBaseInformationDto.setInviteCode(obj.getInviteCode());
                    userBaseInformationDto.setLoseEfficacyTime(obj.getLoseEfficacyTime());
                    userBaseInformationDto.setState(obj.getState());
                    returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                    enterpriseBasicInfo.setMasterDataSystemId(null);
                    enterpriseBasicInfoDto = dozerBeanMapper.map(enterpriseBasicInfo, EnterpriseBasicInfoDto.class);
                    enterpriseBasicInfoDto.setColdChainList((BeanUtil.mapList(dozerBeanMapper,
                            coldChainModel.searchByUserId(obj.getUserId()), ColdchainDTO.class)));
                    enterpriseBasicInfoDto.setEnclosureLists((BeanUtil.mapList(dozerBeanMapper,
                            enterpriseEnclosureMapper.selectList(queryEE), EnterpriseEnclosureDTO.class)));
                    Authorizationbookurl authorizationbookurl =
                            authorizationbookurlModel.searchByUserIdAndChannel(obj.getUserId(), obj.getChannel());
                    if (authorizationbookurl != null) {
                        enterpriseBasicInfoDto.setAuthorizationBookUrl(dozerBeanMapper
                                .map(authorizationbookurl, AuthorizationbookurlDTO.class).getAuthorizationBookUrl());
                    }
                    LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI =
                            new LambdaQueryWrapper<EnterpriseUserInfo>();
                    queryWrapperEUI.eq(EnterpriseUserInfo::getUserId, obj.getUserId());
                    queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getGmtCreate);
                    List<EnterpriseUserInfo> enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
                    for (int i = 0; i < enterpriseUserInfos.size(); i++) {
                        enterpriseUserInfoDto =
                                dozerBeanMapper.map(enterpriseUserInfos.get(i), EnterpriseUserInfoDto.class);
                        enterpriseUserInfoDto.setEnterpriseId(enterpriseUserInfos.get(i).getEntOperatorId());
                        enterpriseUserInfoDtos.add(enterpriseUserInfoDto);
                    }
                    LambdaQueryWrapper<CloudPlatformIdRelation> queryWrapperCP = new LambdaQueryWrapper<>();
                    queryWrapperCP.eq(CloudPlatformIdRelation::getUserId,
                            returnUserInfoDto.getUserBaseInformationDto().getUserId());
                    queryWrapperCP.orderByDesc(CloudPlatformIdRelation::getId);
                    if (cloudPlatformIdRelationMapper.selectCount(queryWrapperCP) > 0) {
                        CloudPlatformIdRelation cloudPlatformIdRelation =
                                cloudPlatformIdRelationMapper.selectList(queryWrapperCP).get(0);
                        enterpriseBasicInfoDto.setPlatformId(cloudPlatformIdRelation.getPlatformId());
                    }
                    // userBaseInformationDto = dozerBeanMapper.map(enterpriseBasicInfo, UserBaseInformationDto.class);
                    returnUserInfoDto.setEnterpriseUserInfoDto(enterpriseUserInfoDtos);
                    returnUserInfoDto.setEnterpriseBasicInfoDto(enterpriseBasicInfoDto);
                    // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                }
            } else if (SystemConstant.USER_TYPE_3.equals(obj.getUserType())) {
                // userBaseInformationDto = dozerBeanMapper.map(obj, UserBaseInformationDto.class);
                // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                List<EnterpriseUserInfoDto> enterpriseUserInfoDtos = new ArrayList<EnterpriseUserInfoDto>();
                LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
                queryWrapperEUI.eq(EnterpriseUserInfo::getUserId, obj.getUserId());
                if (StringUtils.isNotEmpty(requestObject.getUserName())) {
                    queryWrapperEUI.like(EnterpriseUserInfo::getUserName, requestObject.getUserName());
                }
                if (StringUtils.isNotEmpty(requestObject.getUserMobile())) {
                    queryWrapperEUI.like(EnterpriseUserInfo::getTelephone, requestObject.getUserMobile());
                }
                if (StringUtils.isNotEmpty(requestObject.getPapersType())) {
                    queryWrapperEUI.eq(EnterpriseUserInfo::getPapersType, requestObject.getPapersType());
                }
                if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
                    queryWrapperEUI.eq(EnterpriseUserInfo::getPapersNo, requestObject.getPapersNo());
                }
                if (!CommUtils.objectIsNull(requestObject.getEnterpriseId())) {
                    queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, requestObject.getEnterpriseId());
                }
                queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getId);
                List<EnterpriseUserInfo> enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
                for (int i = 0; i < enterpriseUserInfos.size(); i++) {
                    enterpriseUserInfoDto =
                            dozerBeanMapper.map(enterpriseUserInfos.get(i), EnterpriseUserInfoDto.class);
                    enterpriseUserInfoDto.setEnterpriseId(enterpriseUserInfos.get(i).getEntOperatorId());
                    enterpriseUserInfoDtos.add(enterpriseUserInfoDto);
                    // userBaseInformationDto = dozerBeanMapper.map(enterpriseUserInfos.get(i),
                    // UserBaseInformationDto.class);
                    // userBaseInformationDto.setUserAccounts(obj.getUserAccounts());
                    // userBaseInformationDto.setState(obj.getState());
                    // userBaseInformationDto.setUserType(obj.getUserType());
                    // userBaseInformationDto.setBusinessSeqNo(obj.getBusinessSeqNo());
                    // userBaseInformationDto.setEnterpriseId(enterpriseUserInfos.get(i).getEntOperatorId());
                    // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                }
                if (enterpriseUserInfos.size() > 0) {
                    userBaseInformationDto = dozerBeanMapper.map(obj, UserBaseInformationDto.class);
                    userBaseInformationDto.setUserName(enterpriseUserInfos.get(0).getUserName());
                    userBaseInformationDto.setTelephone(enterpriseUserInfos.get(0).getTelephone());
                    userBaseInformationDto.setSgyfId(obj.getSgyfId());
                    returnUserInfoDto.setEnterpriseUserInfoDto(enterpriseUserInfoDtos);
                    returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                }
                // userBaseInformationDto = dozerBeanMapper.map(enterpriseBasicInfo, UserBaseInformationDto.class);
                // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                // returnUserInfoDto.setEnterpriseUserInfoDto(enterpriseUserInfoDtos);
                // if (enterpriseUserInfo != null) {
                // enterpriseUserInfoDto = dozerBeanMapper.map(enterpriseUserInfo, EnterpriseUserInfoDto.class);
                // returnUserInfoDto.setEnterpriseUserInfoDto(enterpriseUserInfoDto);
                // }
            } else if (SystemConstant.USER_TYPE_2.equals(obj.getUserType())) {
                // userBaseInformationDto = dozerBeanMapper.map(obj, UserBaseInformationDto.class);
                // returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, obj.getUserId());
                // if (StringUtils.isNotEmpty(requestObject.getUserName())) {
                // queryWrapperNPB.like(NaturalPersonBaseInformation::getUserName, requestObject.getUserName());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getUserMobile())) {
                // queryWrapperNPB.like(NaturalPersonBaseInformation::getTelephone, requestObject.getUserMobile());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getPapersType())) {
                // queryWrapperNPB.eq(NaturalPersonBaseInformation::getPapersType, requestObject.getPapersType());
                // }
                // if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
                // queryWrapperNPB.eq(NaturalPersonBaseInformation::getPapersNo, requestObject.getPapersNo());
                // }
                queryWrapperNPB.orderByDesc(NaturalPersonBaseInformation::getUserId);
                NaturalPersonBaseInformation naturalPersonBaseInformation =
                        naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
                if (naturalPersonBaseInformation != null) {
                    naturalPersonBaseInformationDto =
                            dozerBeanMapper.map(naturalPersonBaseInformation, NaturalPersonBaseInformationDto.class);
                    userBaseInformationDto =
                            dozerBeanMapper.map(naturalPersonBaseInformation, UserBaseInformationDto.class);
                    userBaseInformationDto.setUserAccounts(obj.getUserAccounts());
                    userBaseInformationDto.setBusinessSeqNo(obj.getBusinessSeqNo());
                    userBaseInformationDto.setUserType(obj.getUserType());
                    userBaseInformationDto.setSgyfId(obj.getSgyfId());
                    returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                    LambdaQueryWrapper<CloudPlatformIdRelation> queryWrapperCP = new LambdaQueryWrapper<>();
                    queryWrapperCP.eq(CloudPlatformIdRelation::getUserId, userBaseInformationDto.getUserId());
                    queryWrapperCP.orderByDesc(CloudPlatformIdRelation::getId);
                    if (cloudPlatformIdRelationMapper.selectCount(queryWrapperCP) > 0) {
                        CloudPlatformIdRelation cloudPlatformIdRelation =
                                cloudPlatformIdRelationMapper.selectList(queryWrapperCP).get(0);
                        naturalPersonBaseInformationDto.setPlatformId(cloudPlatformIdRelation.getPlatformId());
                    }
                    returnUserInfoDto.setNaturalPersonBaseInformationDto(naturalPersonBaseInformationDto);
                }
            } else if (SystemConstant.USER_TYPE_1.equals(obj.getUserType())) {
                LambdaQueryWrapper<EmployeeInformation> queryWrapperEI = new LambdaQueryWrapper<EmployeeInformation>();
                queryWrapperEI.eq(EmployeeInformation::getUserId, obj.getUserId());
                if (StringUtils.isNotEmpty(requestObject.getUserName())) {
                    queryWrapperEI.like(EmployeeInformation::getUserName, requestObject.getUserName());
                }
                if (!CommUtils.objectIsNull(requestObject.getEnterpriseId())) {
                    queryWrapperEI.eq(EmployeeInformation::getOrganizationalId, requestObject.getEnterpriseId());
                }
                if (StringUtils.isNotEmpty(requestObject.getPapersType())) {
                    queryWrapperEI.eq(EmployeeInformation::getPapersType, requestObject.getPapersType());
                }
                if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
                    queryWrapperEI.eq(EmployeeInformation::getPapersNo, requestObject.getPapersNo());
                }
                queryWrapperEI.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperEI.orderByDesc(EmployeeInformation::getId);
                List<EmployeeInformation> employeeInformations = employeeInformationMapper.selectList(queryWrapperEI);
                if (employeeInformations.size() > 0) {
                    userBaseInformationDto = dozerBeanMapper.map(obj, UserBaseInformationDto.class);
                    userBaseInformationDto.setUserName(employeeInformations.get(0).getUserName());
                    userBaseInformationDto.setTelephone(employeeInformations.get(0).getTelephone());
                    userBaseInformationDto.setSgyfId(obj.getSgyfId());
                    returnUserInfoDto.setUserBaseInformationDto(userBaseInformationDto);
                }
            }
            if (returnUserInfoDto.getUserBaseInformationDto() != null) {
                userInfoDtoList.add(getCertInfo(obj, returnUserInfoDto, requestObject.getChannel()));
            }
        }
        pagerInfo.setTotal(page.getTotal());
        return userInfoDtoList;
    }

    /**
     * 查询自然人
     *
     * @param requestObject
     * @return
     */
    public List<NaturalPersonDto> queryNaturalPersonList(QueryNaturalPersonReq requestObject) {
        //查询所有渠道的数据，那么手机号、证件号、客户名称，至少上送一个
        if ("1".equals(requestObject.getAllChannelFlag())) {
            if (StringUtils.isEmpty(requestObject.getTelephone()) && StringUtils.isEmpty(requestObject.getPapersNo())
                    && StringUtils.isEmpty(requestObject.getUserName())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0000_CODE,
                        "手机号、证件号、客户名称，至少上送一个");
            }
        }
        List<NaturalPersonDto> naturalPersonDtos = naturalPersonBaseInformationMapper.queryNaturalPersonList(requestObject);
        long total = naturalPersonBaseInformationMapper.queryNaturalPersonListCounts(requestObject);
        requestObject.getPagerInfo().setTotal(total);
        return naturalPersonDtos;
    }

    // 获取证书相关信息
    public UserInfoDto getCertInfo(UserBaseInformation obj, UserInfoDto returnUserInfoDto, String channel) {
        QueryWrapper<UrEsign> queryWrapperUrEsign = new QueryWrapper<>();
        queryWrapperUrEsign.eq("user_id", obj.getUserId());
        List<UrEsign> urEsigns = urEsignMapper.selectList(queryWrapperUrEsign);
        if (urEsigns != null && urEsigns.size() > 0) {
            List<UrEsignDto> urEsignDtos = new ArrayList<>();
            urEsigns.forEach(urEsign -> {
                urEsignDtos.add(dozerBeanMapper.map(urEsign, UrEsignDto.class));
            });
            returnUserInfoDto.setUrEsignDtos(urEsignDtos);
        }

        QueryWrapper<CertificateManage> queryWrapperCertificateManage = new QueryWrapper<>();
        queryWrapperCertificateManage.eq("user_id", obj.getUserId());
        List<CertificateManage> certificateManages = certificateManageMapper.selectList(queryWrapperCertificateManage);

        if (certificateManages != null && certificateManages.size() > 0) {
            List<CertificateManageDto> certificateManageDtos = new ArrayList<>();
            certificateManages.forEach(certificateManage -> {
                certificateManageDtos.add(dozerBeanMapper.map(certificateManage, CertificateManageDto.class));
            });
            returnUserInfoDto.setCertificateManageDtos(certificateManageDtos);
        }
        queryWrapperUrEsign.eq("channel", channel);
        queryWrapperUrEsign.orderByDesc("gmt_create");
        List<UrEsign> urEsignType = urEsignMapper.selectList(queryWrapperUrEsign);
        queryWrapperCertificateManage.eq("channel", channel);
        queryWrapperCertificateManage.orderByDesc("gmt_create");
        List<CertificateManage> certificateManageType =
                certificateManageMapper.selectList(queryWrapperCertificateManage);
        if (certificateManageType.size() == 0 && urEsignType.size() > 0) {
            returnUserInfoDto.setCertificateType("软证书");
        } else if (certificateManageType.size() > 0 && urEsignType.size() == 0) {
            returnUserInfoDto.setCertificateType("硬证书");
        } else if (certificateManageType.size() == 0 && urEsignType.size() == 0) {
        } else {
            if (urEsignType.get(0).getGmtCreate().isAfter(certificateManageType.get(0).getGmtCreate())) {
                returnUserInfoDto.setCertificateType("软证书");
            } else {
                returnUserInfoDto.setCertificateType("硬证书");
            }
        }
        return returnUserInfoDto;
    }
    /* 获取用户信息 end*/
    /* 获取企业操作人员信息 begin*/

    /**
     * @program: 2020-06-28_userCenter
     * @description: 根据企业名称查询操作员用户信息及角色
     * @author: SongYiFan
     * @create: 2020-06-28 10:56
     **/
    public List<BaseicInfoAndRoleDTO> getInfoByUserName(QueryBaseicInfoAndRoleReq requestObject) {
        // 声明变量 begin
        String companyName = requestObject.getCompanyName();
        PagerInfo pagerInfo = requestObject.getPagerInfo();
        Page<BaseicInfoAndRoleDTO> baseicInfoAndRoleDTOPage =
                new Page<>(pagerInfo.getPageNum(), pagerInfo.getPageSize());
        IPage<BaseicInfoAndRoleDTO> page =
                enterpriseUserInfoMapper.getInfoByUserName(baseicInfoAndRoleDTOPage, companyName);
        pagerInfo.setTotal(page.getTotal());
        return page.getRecords();
    }
    /* 获取企业操作人员信息 end*/
    /* 用户注册 begin */

    /**
     * @author DaiGaoLe
     * @category 用户注册
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer registered(UserRegistrationReq requestObject) {
        if (requestObject.getParentId() == null && (StringUtils.isBlank(requestObject.getPapersType()) || StringUtils.isBlank(requestObject.getPapersNo()))) {
            throw new BusinessException(ErrorMessageConstant.ECUC0064_MESSAGE,
                    ErrorMessageConstant.ECUC0064_CODE);
        }
        if (SystemConstant.USER_TYPE_2.equals(requestObject.getUserType())) {
            //进行个人两要素校验
            ValidPersonBaseReq req = mapper.map(requestObject, ValidPersonBaseReq.class);
            req.setName(requestObject.getUserName());
            req.setIdNo(requestObject.getPapersNo());
            ServiceResult<String> s = esignServiceImpl.individualVerifyBase(req);
            if (StringUtils.isEmpty(s.getResult())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,
                        ErrorMessageConstant.ECUC0038_CODE);
            }
        } else if (SystemConstant.USER_TYPE_0.equals(requestObject.getUserType())) {
//            if(!requestObject.getUserName().equals(requestObject.getCompanyName())){
//                throw new BusinessException(ErrorMessageConstant.ECUC0065_MESSAGE,
//                        ErrorMessageConstant.ECUC0065_CODE);
//            }
            if (requestObject.getParentId() == null) {
                //进行企业两要素校验
                Bureau2FactorsReq req = mapper.map(requestObject, Bureau2FactorsReq.class);
                req.setName(requestObject.getCompanyName());
                if (StringUtils.isNotBlank(requestObject.getBussinessLicenseNo())) {
                    req.setOrgCode(requestObject.getBussinessLicenseNo());
                } else {
                    req.setOrgCode(requestObject.getPapersNo());
                }
                ServiceResult<String> s = esignServiceImpl.bureau2FactorsVerification(req);
                if (StringUtils.isEmpty(s.getResult())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,
                            ErrorMessageConstant.ECUC0038_CODE);
                }
            } else {
                requestObject.setPapersNo("");
                requestObject.setPapersType("");
            }
        }
        // 声明变量 begin
        UserBaseInformation entity = new UserBaseInformation();
        // MD5加密的生活用的盐
        String salt = CommUtils.getSalt();
        // 生成随机数
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        // 渠道
        String channel = requestObject.getChannel();
        String userType = requestObject.getUserType();
        // 用户账号
        String userAccounts = requestObject.getUserAccounts();
        String userPassword = requestObject.getUserPassword();
        if (userType.equals(SystemConstant.USER_TYPE_0)) {// 企业
            userAccounts = uuid.substring(0, 20);
            userPassword = uuid;
        }
        if (StringUtils.isEmpty(userAccounts) || StringUtils.isEmpty(userPassword)) {
            if (SystemConstant.USER_TYPE_2.equals(userType)) {
                throw new BusinessException(ErrorMessageConstant.ECUC0007_MESSAGE, ErrorMessageConstant.ECUC0007_CODE);
            }
        }
        if (SystemConstant.USER_TYPE_2.equals(userType) && !CommUtils.checkPassword(userPassword)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0021_MESSAGE, ErrorMessageConstant.ECUC0021_CODE);
        }
        String telephone = requestObject.getTelephone();
        String userName = requestObject.getUserName();
        String companyName = requestObject.getCompanyName();
        String userTypeList = null;
        Integer integer = null;
        String contacts = requestObject.getContacts();
        String inviteCode = requestObject.getInviteCode();
        // 声明变量 end
        // 2021/10/20 应产融要求取消手机号校验
        // if (!CommUtils.isPhone(telephone)) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        // }

        // 必须是这个顺序不然就在Redis里面的key不一致了
        // requestObject.getTelephone() 这电话也是就是获取邀请码的时候录入的联系人电话的电话。

        // 判断是否是邀请制用户注册 begin
        // QueryWrapper<SystemParameters> queryWrapperSp0 = new QueryWrapper<>();
        // queryWrapperSp0.eq(SystemConstant.SYSTEM_PARAMETERS_CODE, SystemConstant.SYSTEM_PARAMETERS_CODE_0000000004);
        // queryWrapperSp0.eq(SystemConstant.SYSTEM_PARAMETERS_NAME, SystemConstant.SYSTEM_PARAMETERS_NAME_0000000004);
        // List<SystemParameters> systemParameters0 = systemParametersMapper.selectList(queryWrapperSp0);
        //
        // if (systemParameters0 == null || systemParameters0.size() == 0) {
        // throw new BusinessException("系统参数没有配置",ErrorMessageConstant.ECUC0000_CODE);
        // }
        //
        // if (systemParameters0.size() > 1) {
        // throw new BusinessException("系统参数配置异常",ErrorMessageConstant.ECUC0000_CODE);
        // }
        //
        // SystemParameters systemParameter0 = systemParameters0.get(0);
        // if(systemParameter0.getValue().contains(channel)){
        if (StringUtils.isNotEmpty(inviteCode)) {
            // 此处的id没有加上邀请人的用户id
            String id = "";
            QueryWrapper<InviteeInformation> queryWrapperIi = new QueryWrapper<>();
            // queryWrapperIi.eq("user_id", userId);
            if (SystemConstant.USER_TYPE_2.equals(userType)) {
                id = requestObject.getPapersNo() + userName + telephone;
                queryWrapperIi.eq("papers_no", requestObject.getPapersNo());
                queryWrapperIi.eq("contacts", userName);
                queryWrapperIi.eq("user_type", SystemConstant.USER_TYPE_2);
            } else {
                id = companyName + contacts + telephone;
                queryWrapperIi.eq("enterprise_name", companyName);
                queryWrapperIi.eq("contacts", contacts);
                queryWrapperIi.eq("user_type", SystemConstant.USER_TYPE_0);
            }
            queryWrapperIi.eq("contacts_telephone", telephone);
            // 状态必须是0的
            queryWrapperIi.eq("state", "0");
            // 在有效期内
            queryWrapperIi.ge("end_time", LocalDateTime.now());
            List<InviteeInformation> inviteeInformations = inviteeInformationMapper.selectList(queryWrapperIi);

            if (inviteeInformations.size() == 0) {
                throw new BusinessException(ErrorMessageConstant.ECUC0041_MESSAGE, ErrorMessageConstant.ECUC0041_CODE);
            }

            if (inviteeInformations != null && inviteeInformations.size() > 0) {
                // String inviteCode = requestObject.getInviteCode();
                // if (StringUtils.isEmpty(inviteCode)) {
                // throw new BusinessException("当前注册用户为被邀请企业，邀请码不能为空", ErrorMessageConstant.ECUC0000_CODE);
                // }
                // queryWrapperIi.eq("channel", channel);
                // Integer isItTheChannel = inviteeInformationMapper.selectCount(queryWrapperIi);
                // if (isItTheChannel == null || isItTheChannel == 0) {
                // throw new BusinessException("当前注册用户没有在当前系统被邀请", ErrorMessageConstant.ECUC0000_CODE);
                // }

                // 修改验证方式 宋一帆 2020-08-03
                // QueryWrapper<UserBaseInformation> queryWrapperUbi = new QueryWrapper<>();
                // queryWrapperUbi.eq("invite_code", inviteCode);
                // List<UserBaseInformation> userBaseInformations = this.getBaseMapper().selectList(queryWrapperUbi);
                // if (userBaseInformations == null || userBaseInformations.size() == 0) {
                // throw new BusinessException("邀请码不一致", ErrorMessageConstant.ECUC0011_CODE);
                // }
                // id = id + userBaseInformations.get(0).getUserId();
                queryWrapperIi.eq("invite_code", inviteCode);
                Integer isTheChannel = inviteeInformationMapper.selectCount(queryWrapperIi);
                if (isTheChannel == null || isTheChannel == 0) {
                    throw new BusinessException("邀请码不一致", ErrorMessageConstant.ECUC0011_CODE);
                }

                // Add By Liwq On 2020-11-25 Start
                // 跨渠道邀请注册，要校验本次传参channel，是否属于 邀请信息表.可用渠道 字段里面。
                if (isTheChannel != null || isTheChannel > 0) {
                    InviteeInformation tempInviteInfo = inviteeInformationMapper.selectList(queryWrapperIi).get(0);
                    // 可用渠道为空，便给报错，当前注册用户没有在当前系统被邀请。
                    if (StringUtils.isEmpty(tempInviteInfo.getAvailableChannel())) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0051_MESSAGE,
                                ErrorMessageConstant.ECUC0051_CODE);
                    }
                    // 可用渠道不为空，但是当前渠道不属于可用渠道的话，也给报错。
                    if (tempInviteInfo.getAvailableChannel().indexOf(requestObject.getChannel()) == -1) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0051_MESSAGE,
                                ErrorMessageConstant.ECUC0051_CODE);
                    }
                }
                // Add By Liwq On 2020-11-25 End

                Integer userId = inviteeInformationMapper.selectOne(queryWrapperIi).getUserId();
                id = id + userId;
                String redisKey = CommUtils.getRedisKey("uubi", "inviteCode", id);
                String key = redisson.get(redisKey);
                IfpLogger.info("**********用户注册,redisKey:", redisKey);
                IfpLogger.info("**********用户注册,redisValue:", key);
                if (StringUtils.isEmpty(key)) {
                    throw new BusinessException("邀请码已经过期请重新获取", ErrorMessageConstant.ECUC0000_CODE);
                }
            }
        } else {
            QueryWrapper<InviteeInformation> queryWrapperIi = new QueryWrapper<>();
            if (SystemConstant.USER_TYPE_2.equals(userType)) {
                queryWrapperIi.eq("papers_no", requestObject.getPapersNo());
                queryWrapperIi.eq("contacts", userName);
                queryWrapperIi.eq("user_type", SystemConstant.USER_TYPE_2);
            } else {
                queryWrapperIi.eq("enterprise_name", companyName);
                queryWrapperIi.eq("contacts", contacts);
                queryWrapperIi.eq("user_type", SystemConstant.USER_TYPE_0);
            }
            queryWrapperIi.eq("contacts_telephone", telephone);
            // queryWrapperIi.eq("channel",channel);
            // 状态必须是0的
            queryWrapperIi.eq("state", "0");
            // 在有效期内
            queryWrapperIi.ge("end_time", LocalDateTime.now());
            List<InviteeInformation> inviteeInformations = inviteeInformationMapper.selectList(queryWrapperIi);
            if (inviteeInformations.size() > 0) {
                throw new BusinessException("该用户已被邀请，请填写邀请码", ErrorMessageConstant.ECUC0000_CODE);
            }
        }
        // 判断是否是邀请制用户注册 End

        if (SystemConstant.USER_TYPE_2.equals(userType)) { // 自然人
            // 若为自然人用户注册，且证件类型不为身份证时，则跳过原有的身份证规则校验
            if (StringUtils.isNotEmpty(requestObject.getPapersNo())
                    && SystemConstant.PAPERS_TYPE_04.equals(requestObject.getPapersType())) {
                if (!CommUtils.isIdNumber(requestObject.getPapersNo())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0016_MESSAGE,
                            ErrorMessageConstant.ECUC0016_CODE);
                }
            }
        }

        QueryWrapper<SystemParameters> queryWrapperSp = new QueryWrapper<>();
        queryWrapperSp.eq(SystemConstant.SYSTEM_PARAMETERS_CODE, SystemConstant.SYSTEM_PARAMETERS_CODE_0000000003);
        queryWrapperSp.eq(SystemConstant.SYSTEM_PARAMETERS_NAME, SystemConstant.SYSTEM_PARAMETERS_NAME_0000000003);
        List<SystemParameters> systemParameters = systemParametersMapper.selectList(queryWrapperSp);
        if (systemParameters.size() > 1) {
            throw new BusinessException("系统参数配置异常", ErrorMessageConstant.ECUC0000_CODE);
        }
        userTypeList = systemParameters.get(0).getValue();
        if (userTypeList == null) {
            throw new BusinessException("用户类型有效性集合没有维护", ErrorMessageConstant.ECUC0026_CODE);
        } else {
            if (!userTypeList.contains(userType)) {
                throw new BusinessException("用户类型：" + userType + "无效", ErrorMessageConstant.ECUC0026_CODE);
            }
        }
        QueryWrapper<UserBaseInformation> queryWrapper = new QueryWrapper<>();
        // queryWrapper.isNull("delete_channel_users");
        queryWrapper.eq("user_accounts", userAccounts);
        integer = this.getBaseMapper().selectCount(queryWrapper);
        if (integer > 0) {
            throw new BusinessException("账号：" + userAccounts + "已经存在", ErrorMessageConstant.ECUC0001_CODE);
        }

        if (userType.equals(SystemConstant.USER_TYPE_0)) {// 企业
            // LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            // queryWrapperEBI.eq(EnterpriseBasicInfo::getTelephone, telephone);
            // if (enterpriseBasicInfoMapper.selectCount(queryWrapperEBI) > 0) {
            // throw new BusinessException("手机号：" + telephone + "已经存在", ErrorMessageConstant.ECUC0024_CODE);
            // }
        } else if (userType.equals(SystemConstant.USER_TYPE_2)) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNBI =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNBI.eq(NaturalPersonBaseInformation::getTelephone, telephone);
            // queryWrapperNBI.isNotNull(NaturalPersonBaseInformation::getDeleteChannelUsers);
            if (naturalPersonBaseInformationMapper.selectCount(queryWrapperNBI) > 0) {
                throw new BusinessException("手机号：" + telephone + "已经存在", ErrorMessageConstant.ECUC0024_CODE);
            }
        }
        // queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("user_type", userType);
        // queryWrapper.eq("telephone", telephone);
        //// queryWrapper.eq("channel", channel);
        //
        // integer = this.getBaseMapper().selectCount(queryWrapper);
        // if (integer > 0) {
        // throw new BusinessException("手机号：" + telephone + "已经存在",ErrorMessageConstant.ECUC0024_CODE);
        // }

        if (userType.equals(SystemConstant.USER_TYPE_0)) {// 企业
            // queryWrapper = new QueryWrapper<>();
            // queryWrapper.eq("user_name", userName);
            // integer = this.getBaseMapper().selectCount(queryWrapper);
            if (StringUtils.isNotBlank(requestObject.getPapersNo())) {
                LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
                queryWrapperEBI.eq(EnterpriseBasicInfo::getPapersNo, requestObject.getPapersNo());
                if (enterpriseBasicInfoMapper.selectCount(queryWrapperEBI) > 0) {
                    throw new BusinessException("用户(" + requestObject.getPapersNo() + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
                }
            }
            QueryWrapper<EnterpriseBasicInfo> queryWrapperBI = new QueryWrapper<>();
            queryWrapperBI.eq("company_name", companyName);
            integer = enterpriseBasicInfoMapper.selectCount(queryWrapperBI);
            if (integer > 0) {
                throw new BusinessException("用户(" + companyName + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
            }
        } else if (userType.equals(SystemConstant.USER_TYPE_2)) {// 个人
            if (StringUtils.isNotEmpty(requestObject.getPapersNo())) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNP =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersType, requestObject.getPapersType());
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersNo, requestObject.getPapersNo());
                integer = naturalPersonBaseInformationMapper.selectCount(queryWrapperNP);
                if (integer > 0) {
                    throw new BusinessException("用户(" + userName + ")已经注册", ErrorMessageConstant.ECUC0025_CODE);
                }
            }
        }
        entity.setBusinessSeqNo(requestObject.getTraceId());
        // 是企业用户
        entity.setUserType(requestObject.getUserType());
        entity.setUserAccounts(userAccounts);
        entity.setSgyfId(requestObject.getSgyfId());
        entity.setUserPassword(CommUtils.getMd5SaltPassword(userPassword, salt));
        // entity.setTelephone(requestObject.getTelephone());
        // entity.setUserName(requestObject.getUserName());
        // entity.setPapersType(requestObject.getPapersType());
        // entity.setPapersNo(requestObject.getPapersNo());
        // 2020-07-28 宋一帆 增加非三证
        // entity.setBussinessLicenseNo(requestObject.getBussinessLicenseNo());
        // entity.setTaxRegistrationNo(requestObject.getTaxRegistrationNo());
        entity.setChannel(channel);
        entity.setLoseEfficacyTime(
                commUtils.getSystemParameterValueOne(SystemConstant.SYSTEM_PARAMETERS_CODE_0000000001, "loseEfficacyTime"));
        // entity.setEnteredInviteCode(requestObject.getInviteCode());
        entity.setSalt(salt);
        // if (requestObject.getCustomerId() != null) {
        // entity.setCustomerManagerId(requestObject.getCustomerId());
        // }
        entity.setGmtCreate(LocalDateTime.now());
        entity.setGmtModified(LocalDateTime.now());
        entity.setModifiedBy(requestObject.getOperationUserId());
        entity.setCreateBy(requestObject.getOperationUserId());
        this.save(entity);

        // this.updateById(entity);

        // 注册完后，若是邀请注册的，那么注册完后，将邀请码设置为失效状态1
        updateExpireState(requestObject);

        // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
        if (SystemConstant.USER_TYPE_0.equals(userType)) {// 0-企业用户
            insertEnterpriseBasicInfo(entity, requestObject);
        }

        if (SystemConstant.USER_TYPE_2.equals(userType)) {// 2-个人用户
            insertNaturalPersonBaseInformation(entity, requestObject);
        }

        // add by liwq on 2021-07-07 start
        // 将数据同步到云平台
        cloudPlatformAsync.mergeDataToCloudPlatform(requestObject, entity.getUserId());
        // add by liwq on 2021-07-07 end

        return entity.getUserId();
    }

    /**
     * 用户注册服务用,更新失效标记为1
     *
     * @param requestObject
     * @return
     */
    private void updateExpireState(UserRegistrationReq requestObject) {
        QueryWrapper<InviteeInformation> queryWrapperIi = new QueryWrapper<>();
        if (SystemConstant.USER_TYPE_2.equals(requestObject.getUserType())) {
            queryWrapperIi.eq("papers_no", requestObject.getPapersNo());
            queryWrapperIi.eq("contacts", requestObject.getUserName());
        } else {
            queryWrapperIi.eq("enterprise_name", requestObject.getCompanyName());
            queryWrapperIi.eq("contacts", requestObject.getContacts());
        }
        queryWrapperIi.eq("contacts_telephone", requestObject.getTelephone());
        queryWrapperIi.eq("invite_code", requestObject.getInviteCode());
        // 相同企业名称，联系人，联系电话，邀请码，在邀请信息表里有数据的话，只可能是一条
        List<InviteeInformation> inviteeInformations = inviteeInformationMapper.selectList(queryWrapperIi);
        InviteeInformation i = null;
        // 找到，并且当前时间大于失效时间的话，便更新；找不到说明不是邀请制，邀请信息表里没数据,不用更新；
        if (inviteeInformations != null && inviteeInformations.size() > 0) {
            i = inviteeInformations.get(0);
            i.setState(SystemConstant.UR_INVITEE_INFORMATION_STATE_1);
            inviteeInformationMapper.updateById(i);
        }
    }

    /**
     * 补录邀请码服务用,更新失效标记为1
     *
     * @param requestObject
     * @return
     */
    private void updateExpireStateForSupplement(SupplementInvitationCode requestObject) {
        QueryWrapper<InviteeInformation> queryWrapperIi = new QueryWrapper<>();
        queryWrapperIi.eq("enterprise_name", requestObject.getOppositeName());
        queryWrapperIi.eq("contacts", requestObject.getOppositeContactPerson());
        queryWrapperIi.eq("contacts_telephone", requestObject.getOppositeContactPhone());
        queryWrapperIi.eq("invite_code", requestObject.getInviteCode());
        // 相同企业名称，联系人，联系电话，邀请码，在邀请信息表里有数据的话，只可能是一条
        List<InviteeInformation> inviteeInformations = inviteeInformationMapper.selectList(queryWrapperIi);
        InviteeInformation i = null;
        // 更新失效标记为1；
        if (inviteeInformations != null && inviteeInformations.size() > 0) {
            i = inviteeInformations.get(0);
            i.setState(SystemConstant.UR_INVITEE_INFORMATION_STATE_1);
            inviteeInformationMapper.updateById(i);
        }
    }

    /**
     * 判断邀请码有无失效
     *
     * @return
     */
    private boolean judgeExpireOrNot(LocalDateTime endTime) {
        if (endTime == null) {
            return false;
        }
        LocalDateTime now = LocalDateTime.now();
        Duration duration = Duration.between(endTime, now);
        long millis = duration.toMillis();// 相差毫秒数
        // 当前时间 大于 生效结束时间，代表已经失效
        if (millis > 0) {
            return true;
        } else {
            return false;
        }
    }

    private void insertEnterpriseBasicInfo(UserBaseInformation userBaseInformation, UserRegistrationReq requestObject) {
        if (StringUtils.isEmpty(requestObject.getCompanyName())) {
            throw new BusinessException(ErrorMessageConstant.ECUC0048_MESSAGE, ErrorMessageConstant.ECUC0048_CODE);
        }
        EnterpriseBasicInfo entity = new EnterpriseBasicInfo();
        entity.setUserId(userBaseInformation.getUserId());
        dozerBeanMapper.map(requestObject, entity);
        entity.setCustomerManagerId(requestObject.getCustomerId());
        entity.setEnteredInviteCode(requestObject.getInviteCode());
        entity.setUserName(requestObject.getCompanyName());
        entity.setModifiedBy(requestObject.getOperationUserId());
        entity.setCreateBy(requestObject.getOperationUserId());
        entity.setGmtModified(LocalDateTime.now());
        entity.setAuthorizedChannels(entity.getChannel());
        Integer formatId = requestObject.getFormatId();
        if (formatId != null) {
            if (!organizationManagementModel.checkFormatId(formatId, requestObject.getChannel())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
            }
            entity.setAuthorizedFormats(formatId.toString());
        }
        enterpriseBasicInfoMapper.insert(entity);
        // 2020-07-21新增，添加企业用户时同时添加员工
        // EnterpriseUserInfo userInfo = new EnterpriseUserInfo();
        // userInfo.setUserId(userBaseInformation.getUserId());
        // dozerBeanMapper.map(requestObject, userInfo);
        // userInfo.setModifiedBy(requestObject.getOperationUserId());
        // userInfo.setCreateBy(requestObject.getOperationUserId());
        // userInfo.setGmtModified(LocalDateTime.now());
        // userInfo.setEntOperatorId(userBaseInformation.getUserId());
        // enterpriseUserInfoMapper.insert(userInfo);
    }

    private void insertNaturalPersonBaseInformation(UserBaseInformation userBaseInformation,
                                                    UserRegistrationReq requestObject) {
        NaturalPersonBaseInformation entity = new NaturalPersonBaseInformation();
        entity.setUserId(userBaseInformation.getUserId());
        dozerBeanMapper.map(requestObject, entity);
        entity.setEnteredInviteCode(requestObject.getInviteCode());
        entity.setModifiedBy(requestObject.getOperationUserId());
        entity.setCreateBy(requestObject.getOperationUserId());
        entity.setGmtModified(LocalDateTime.now());
        entity.setAuthorizedChannels(entity.getChannel());
        Integer formatId = requestObject.getFormatId();
        if (formatId != null) {
            if (!organizationManagementModel.checkFormatId(formatId, requestObject.getChannel())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
            }
            entity.setAuthorizedFormats(formatId.toString());
        }
        naturalPersonBaseInformationMapper.insert(entity);
    }
    /* 用户注册 end*/

    /* 加解锁定用户 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 加解锁定用户事务层
     * @author: DaiGaoLe
     * @create: 2019-10-22 14:23
     **/
    @Transactional(rollbackFor = Exception.class)
    public String unlockOrLocksUser(UnlockOrLocksUserReq requestObject) {
        // 声明变量 begin
        String returnsResult = SystemConstant.SYSTEM_SUCCESS;
        // 用户id
        Integer userId = requestObject.getUserId();
        Integer operationUserId = new Integer(requestObject.getOperationUserId());

        UserBaseInformation user = this.getById(userId);
        if (user == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }

        String operationType = requestObject.getOperationType();
        String channel = requestObject.getChannel();
        String userType = user.getUserType();
        Integer enterpriseId = requestObject.getEnterpriseId();

        // 声明变量 begin
        String channelUnlockState = null;
        //2022-09-21 syf新增锁定业态id
        Integer formatUnlockState = null;
        Integer formatId = requestObject.getFormatId();
        if (userType.equals(SystemConstant.USER_TYPE_0)) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            if (enterpriseBasicInfo == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            EnterpriseBasicInfoHistory enterpriseBasicInfoHistory =
                    dozerBeanMapper.map(enterpriseBasicInfo, EnterpriseBasicInfoHistory.class);
            enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
            channelUnlockState = enterpriseBasicInfo.getChannelUnlockState();
            //2022-09-21 syf新增锁定业态id
            formatUnlockState = enterpriseBasicInfo.getFormatUnlockState();
            // 操作类型(1-加锁，0-解锁)
            if (SystemConstant.OPERATION_TYPE_1.equals(operationType)) {
                if (SystemConstant.OPERATION_TYPE_1.equals(enterpriseBasicInfo.getIsUnlock())) {
                    throw new BusinessException("该用户已被锁定");
                }
                if(!enterpriseBasicInfo.getAuthorizedChannels().contains(channel)){
                    throw new BusinessException("请先进行共有用户授权");
                }
                if(formatId!=null){
                    if(organizationManagementModel.checkFormatId(formatId,channel)){
                        if(enterpriseBasicInfo.getAuthorizedFormats()!=null&&enterpriseBasicInfo.getAuthorizedFormats().contains(formatId.toString())){
                            enterpriseBasicInfo.setFormatUnlockState(formatId);
                        } else {
                            throw new BusinessException(ErrorMessageConstant.ECUC0068_MESSAGE, ErrorMessageConstant.ECUC0068_CODE);
                        }
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                    }
                }
                enterpriseBasicInfo.setIsUnlock(SystemConstant.OPERATION_TYPE_1);
                enterpriseBasicInfo.setChannelUnlockState(channel);
            } else {
                if (SystemConstant.OPERATION_TYPE_0.equals(enterpriseBasicInfo.getIsUnlock())) {
                    throw new BusinessException("用户没有被锁定");
                }
                if(!channel.equals(enterpriseBasicInfo.getChannelUnlockState())){
                    throw new BusinessException("只有加锁渠道可以解锁");
                }
                if(formatUnlockState!=null){
                    if(formatUnlockState.equals(formatId)){
                        enterpriseBasicInfo.setFormatUnlockState(null);
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                    }
                }
                enterpriseBasicInfo.setChannelUnlockState("");
                enterpriseBasicInfo.setIsUnlock(SystemConstant.OPERATION_TYPE_0);
            }
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapper.eq(EnterpriseBasicInfo::getUserId, userId);
            enterpriseBasicInfoMapper.update(enterpriseBasicInfo, queryWrapper);
        } else if (userType.equals(SystemConstant.USER_TYPE_2)) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNBI =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNBI.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation naturalPersonBaseInformation =
                    naturalPersonBaseInformationMapper.selectOne(queryWrapperNBI);
            if (naturalPersonBaseInformation == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            UserBaseInformationHistory userBaseInformationHistory =
                    dozerBeanMapper.map(user, UserBaseInformationHistory.class);
            userBaseInformationHistoryMapper.insert(userBaseInformationHistory);
            Integer userHistoryId = userBaseInformationHistory.getId();
            NaturalPersonBaseInformationHistory naturalPersonBaseInformationHistory =
                    dozerBeanMapper.map(naturalPersonBaseInformation, NaturalPersonBaseInformationHistory.class);
            naturalPersonBaseInformationHistory.setId(userHistoryId);
            naturalPersonBaseInformationHistoryMapper.insert(naturalPersonBaseInformationHistory);
            //2022-09-21 syf新增锁定业态id
            formatUnlockState = naturalPersonBaseInformation.getFormatUnlockState();
            // 操作类型(1-加锁，0-解锁)
            if (SystemConstant.OPERATION_TYPE_1.equals(operationType)) {
                if (SystemConstant.OPERATION_TYPE_1.equals(naturalPersonBaseInformation.getIsUnlock())) {
                    throw new BusinessException("该用户已被锁定");
                }
                if(!naturalPersonBaseInformation.getAuthorizedChannels().contains(channel)){
                    throw new BusinessException("请先进行共有用户授权");
                }
                if(formatId!=null){
                    if(organizationManagementModel.checkFormatId(formatId,channel)){
                        if(naturalPersonBaseInformation.getAuthorizedFormats()!=null&&naturalPersonBaseInformation.getAuthorizedFormats().contains(formatId.toString())){
                            naturalPersonBaseInformation.setFormatUnlockState(formatId);
                        } else {
                            throw new BusinessException(ErrorMessageConstant.ECUC0068_MESSAGE, ErrorMessageConstant.ECUC0068_CODE);
                        }
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                    }
                }
                naturalPersonBaseInformation.setIsUnlock(SystemConstant.OPERATION_TYPE_1);
                naturalPersonBaseInformation.setChannelUnlockState(channel);
            } else {
                if (SystemConstant.OPERATION_TYPE_0.equals(naturalPersonBaseInformation.getIsUnlock())) {
                    throw new BusinessException("用户没有被锁定");
                }
                if(!channel.equals(naturalPersonBaseInformation.getChannelUnlockState())){
                    throw new BusinessException("只有加锁渠道可以解锁");
                }
                if(formatUnlockState!=null){
                    if(formatUnlockState.equals(formatId)){
                        naturalPersonBaseInformation.setFormatUnlockState(null);
                    } else {
                        throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                    }
                }
                naturalPersonBaseInformation.setChannelUnlockState("");
                naturalPersonBaseInformation.setIsUnlock(SystemConstant.OPERATION_TYPE_0);
            }
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapper =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapper.eq(NaturalPersonBaseInformation::getUserId, userId);
            naturalPersonBaseInformationMapper.update(naturalPersonBaseInformation, queryWrapper);
        } else if (userType.equals(SystemConstant.USER_TYPE_1)) {
            if (CommUtils.objectIsNull(enterpriseId)) {
                throw new BusinessException("enterpriseId不能为空", ErrorMessageConstant.ECUC0001_CODE);
            }
            LambdaQueryWrapper<EmployeeInformation> queryWrapperEI = new LambdaQueryWrapper<EmployeeInformation>();
            queryWrapperEI.eq(EmployeeInformation::getUserId, userId);
            queryWrapperEI.eq(EmployeeInformation::getOrganizationalId, enterpriseId);
            queryWrapperEI.eq(EmployeeInformation::getChannel, channel);
            queryWrapperEI.eq(EmployeeInformation::getIsDelete, SystemConstant.IS_DELETE_0);
            EmployeeInformation employeeInformation = employeeInformationMapper.selectOne(queryWrapperEI);
            if (employeeInformation == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            String unlockChannelUsers = employeeInformation.getIsUnlock();
            if (SystemConstant.OPERATION_TYPE_1.equals(operationType)) {
                employeeInformation.setIsUnlock(SystemConstant.UNLOCK_STATE_1);
            } else {
                employeeInformation.setIsUnlock(SystemConstant.UNLOCK_STATE_0);
            }
            employeeInformation.setGmtModified(LocalDateTime.now());
            employeeInformation.setModifiedBy(operationUserId);
            employeeInformationMapper.update(employeeInformation, queryWrapperEI);
        } else if (userType.equals(SystemConstant.USER_TYPE_3)) {
            if (CommUtils.objectIsNull(enterpriseId)) {
                throw new BusinessException("enterpriseId不能为空", ErrorMessageConstant.ECUC0001_CODE);
            }
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapperEUI.eq(EnterpriseUserInfo::getUserId, userId);
            queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
            queryWrapperEUI.eq(EnterpriseUserInfo::getChannel, channel);
            queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            EnterpriseUserInfo enterpriseUserInfo = enterpriseUserInfoMapper.selectOne(queryWrapperEUI);
            if (enterpriseUserInfo == null) {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            String unlockChannelUsers = enterpriseUserInfo.getIsUnlock();
            if (SystemConstant.OPERATION_TYPE_1.equals(operationType)) {
                enterpriseUserInfo.setIsUnlock(SystemConstant.UNLOCK_STATE_1);
            } else {
                enterpriseUserInfo.setIsUnlock(SystemConstant.UNLOCK_STATE_0);
            }
            enterpriseUserInfo.setGmtModified(LocalDateTime.now());
            enterpriseUserInfo.setModifiedBy(operationUserId);
            enterpriseUserInfoMapper.update(enterpriseUserInfo, queryWrapperEUI);
        }
        user.setModifiedBy(operationUserId);
        user.setGmtModified(LocalDateTime.now());
        this.updateById(user);
        return returnsResult;
    }
    /* 加解锁定用户 end */

    /* 用户认证 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 用户认证model
     * @author: DaiGaoLe
     * @create: 2019-10-21 14:30
     **/
    @Transactional(rollbackFor = Exception.class)
    public String userAuthentication(UserAuthentication requestObject) {
        // 声明变量 begin
        Integer userId = requestObject.getUserId();
        // Integer roleId = requestObject.getRoleId();
        String channel = requestObject.getChannel();
        String userType = null;
        Integer operationUserId = requestObject.getOperationUserId();
        Integer userHistoryId = null;
        Integer tempUserId = null;
        String oldPapersNo = null;
        String newPapersNo = requestObject.getPapersNo();
        // 声明变量 end

        UserBaseInformation ubi = userBaseInformationMapper.selectById(userId);
        if (ubi == null) {
            throw new BusinessException("用户(" + userId + ")没有在用户中台注册");
        }
        userType = ubi.getUserType();
        if (SystemConstant.USER_TYPE_0.equals(userType)) {
            // if(CommUtils.objectIsNull(requestObject.getRoleId())) {
            // throw new BusinessException("roleId=被认证用户角色id不能为空");
            // }
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo ebi = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI); // 2020-07-28 宋一帆 增加非三证校验

            if (StringUtils.isNotEmpty(ebi.getBussinessLicenseNo())
                    && StringUtils.isNotEmpty(requestObject.getBussinessLicenseNo())
                    && !requestObject.getBussinessLicenseNo().equals(ebi.getBussinessLicenseNo())) {
                throw new BusinessException("营业执照编号不一致");
            }

            if (StringUtils.isNotEmpty(ebi.getTaxRegistrationNo())
                    && StringUtils.isNotEmpty(requestObject.getTaxRegistrationNo())
                    && !requestObject.getTaxRegistrationNo().equals(ebi.getTaxRegistrationNo())) {
                throw new BusinessException("税务登记证编号不一致");
            }

            if (StringUtils.isNotEmpty(requestObject.getUserName())
                    && !requestObject.getUserName().equals(ebi.getUserName())) {
                throw new BusinessException("用户名称不一致");
            }

            if (StringUtils.isNotEmpty(ebi.getPapersType()) && StringUtils.isNotEmpty(requestObject.getPapersType())
                    && !requestObject.getPapersType().equals(ebi.getPapersType())) {
                throw new BusinessException("用户证件类型不一致");
            }

            if (StringUtils.isNotEmpty(ebi.getPapersNo()) && StringUtils.isNotEmpty(requestObject.getPapersNo())
                    && !requestObject.getPapersNo().equals(ebi.getPapersNo())) {
                throw new BusinessException("用户证件编号不一致");
            }

            //add by liwq on 2022-10-12 start
            //修改企业客户时，增加校验逻辑：判断该企业客户是否已锁定，若未锁定，则阻断交易；若已经锁定，则继续判断当前渠道是否与加锁渠道一致，若不一致，阻断交易，若一致，则继续原修改逻辑。
            if (ebi != null) {
                //是否锁定0:正常1:锁定
                String isUnLock = ebi.getIsUnlock();
                if (!"1".equals(isUnLock)) {
                    throw new BusinessException("该企业客户未锁定，禁止修改！", ErrorMessageConstant.ECUC0002_MESSAGE);
                }
                if ("1".equals(isUnLock)) {
                    String channelUnlockState = ebi.getChannelUnlockState();
                    if (!requestObject.getChannel().equals(channelUnlockState)) {
                        throw new BusinessException("当前渠道与加锁渠道不一致，请检查！", ErrorMessageConstant.ECUC0002_MESSAGE);
                    }
                }
            }
            //add by liwq on 2022-10-12 end


            oldPapersNo = ebi.getPapersNo();
            List<EnterpriseEnclosure> enclosureList = new ArrayList<EnterpriseEnclosure>();
            List<EnterpriseEnclosureReq> oldEnclosureList = requestObject.getEnclosureLists();
            if (oldEnclosureList != null) {
                Iterator<EnterpriseEnclosureReq> iterator = oldEnclosureList.iterator();
                while (iterator.hasNext()) {
                    EnterpriseEnclosureReq enclosureReq = iterator.next();
                    EnterpriseEnclosure enclosure = new EnterpriseEnclosure();
                    enclosure.setEnclosureType(enclosureReq.getEnclosureType());
                    enclosure.setEnclosureUrl(enclosureReq.getEnclosureUrl());
                    enclosure.setUserId(userId);
                    enclosure.setCreateBy(operationUserId);
                    enclosure.setGmtCreate(LocalDateTime.now());
                    enclosure.setModifiedBy(operationUserId);
                    enclosure.setGmtModified(LocalDateTime.now());
                    enclosure.setChannel(channel);
                    enclosureList.add(enclosure);
                }
                enterpriseEnclosureModel.saveBatch(enclosureList);
            }
        } else if (SystemConstant.USER_TYPE_2.equals(userType)) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation npb = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
            if (StringUtils.isNotEmpty(requestObject.getUserName())
                    && !requestObject.getUserName().equals(npb.getUserName())) {
                throw new BusinessException("用户名称不一致");
            }

            if (StringUtils.isNotEmpty(npb.getPapersType()) && StringUtils.isNotEmpty(requestObject.getPapersType())
                    && !requestObject.getPapersType().equals(npb.getPapersType())) {
                throw new BusinessException("用户证件类型不一致");
            }

            if (StringUtils.isNotEmpty(npb.getPapersNo()) && StringUtils.isNotEmpty(requestObject.getPapersNo())
                    && !requestObject.getPapersNo().equals(npb.getPapersNo())) {
                throw new BusinessException("用户证件编号不一致");
            }
            if (StringUtils.isNotBlank(requestObject.getPapersNo())) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNP =
                        new LambdaQueryWrapper<NaturalPersonBaseInformation>();
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersType, requestObject.getPapersType());
                queryWrapperNP.eq(NaturalPersonBaseInformation::getPapersNo, requestObject.getPapersNo());
                queryWrapperNP.ne(NaturalPersonBaseInformation::getUserId, userId);
                if (naturalPersonBaseInformationMapper.selectCount(queryWrapperNP) > 0) {
                    throw new BusinessException("用户(" + requestObject.getPapersNo() + ")已经注册",
                            ErrorMessageConstant.ECUC0025_CODE);
                }
            }
            oldPapersNo = npb.getPapersNo();
        } else {
            throw new BusinessException("用户不是企业用户或自然人用户");
        }
        /*
         * 如果用户的状态不是游客状态 提示渠道不能上传认真信息
         * 为了防止恶意修改用户信息
         * */
        if (!SystemConstant.USER_STATE_0.equals(ubi.getState())) {
            throw new BusinessException("用户非游客状态");
        }
        // 用户存在途任务的时候不能上传认证数据
        // boolean joinUnfinishedProcess = generalService.isJoinUnfinishedProcess(userId, requestObject);
        // if (joinUnfinishedProcess) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0004_MESSAGE, ErrorMessageConstant.ECUC0004_CODE);
        // }
        String tempChannel = ubi.getChannel();
        UserBaseInformationHistory userBaseInformationHistory =
                dozerBeanMapper.map(ubi, UserBaseInformationHistory.class);
        userBaseInformationHistoryMapper.insert(userBaseInformationHistory);
        userHistoryId = userBaseInformationHistory.getId();
        dozerBeanMapper.map(requestObject, ubi);
        ubi.setChannel(tempChannel);
        ubi.setGmtModified(LocalDateTime.now());
        ubi.setModifiedBy(operationUserId);
        ubi.setState(SystemConstant.USER_STATE_6);
        userBaseInformationMapper.updateById(ubi);
        // EnterpriseBasicInfoHistory enterpriseBasicInfoHistory = dozerBeanMapper.map(ebi,
        // EnterpriseBasicInfoHistory.class);
        // enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
        // userHistoryId = userBaseInformationHistory.getId();
        // dozerBeanMapper.map(requestObject, ebi);
        // ebi.setChannel(tempChannel);
        // ebi.setGmtModified(LocalDateTime.now());
        // ebi.setModifiedBy(operationUserId);
        // enterpriseBasicInfoMapper.updateById(ebi);

        // 获取自然人客户附属信息
        NaturalPersonBaseInformation naturalPersonBaseInformation =
                dozerBeanMapper.map(requestObject, NaturalPersonBaseInformation.class);
        // 获取对公客户附属信息
        EnterpriseBasicInfo enterpriseBasicInfo = dozerBeanMapper.map(requestObject, EnterpriseBasicInfo.class);
        // EnterpriseUserInfo enterpriseUserInfo = dozerBeanMapper.map(requestObject, EnterpriseUserInfo.class);
        // enterpriseUserInfo.setPapersType(requestObject.getAdminCertificateType());
        // enterpriseUserInfo.setPapersNo(requestObject.getAdminCertificateNo());
        // enterpriseUserInfo.setUserName(requestObject.getAdminName());
        // enterpriseUserInfo.setAdminLicenseUrl(requestObject.getAdminLicenseUrl());
        // enterpriseUserInfo.setEmail(requestObject.getAdminMail());
        // enterpriseUserInfo.setTelephone(requestObject.getAdminTelephone());
        // 用户数据格式校验
        dataFormatCheck(naturalPersonBaseInformation, enterpriseBasicInfo, ubi);
        // EnterpriseUserInfo eui = new EnterpriseUserInfo();
        if (SystemConstant.USER_TYPE_0.equals(userType)) {
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, userId);
            queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getId);
            List<EnterpriseUserInfo> EnterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
            if (EnterpriseUserInfos.size() > 0) {
                tempUserId = EnterpriseUserInfos.get(0).getUserId();
                // eui = getEnterpriseUserInfo(tempChannel, EnterpriseUserInfos.get(0).getUserId(), userId);
            }
        }
        // if (ebi == null && SystemConstant.USER_TYPE_0.equals(userType)) {// 没有保存过企业附属信息表,不存在该情况
        // enterpriseUserInfo.setUserId(userId);
        // enterpriseUserInfo.setCreateBy(operationUserId);
        // enterpriseUserInfo.setGmtModified(LocalDateTime.now());
        // enterpriseUserInfo.setModifiedBy(operationUserId);
        // enterpriseUserInfo.setEntOperatorId(userId);
        // enterpriseUserInfoMapper.insert(enterpriseUserInfo);
        // }

        // if (eui != null && SystemConstant.USER_TYPE_0.equals(userType)) {
        // EnterpriseUserInfoHistory enterpriseUserInfoHistory =
        // dozerBeanMapper.map(eui, EnterpriseUserInfoHistory.class);
        // enterpriseUserInfoHistory.setId(userHistoryId);
        // enterpriseUserInfoHistoryMapper.insert(enterpriseUserInfoHistory);
        // dozerBeanMapper.map(requestObject, eui);
        // eui.setUserId(tempUserId);
        // eui.setGmtModified(LocalDateTime.now());
        // eui.setModifiedBy(operationUserId);
        // LambdaQueryWrapper<EnterpriseUserInfo> queryEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
        // queryEUI.eq(EnterpriseUserInfo::getId, eui.getId());
        // enterpriseUserInfoMapper.update(eui, queryEUI);
        // }
        if (SystemConstant.USER_TYPE_0.equals(userType)) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo ebi = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            String oldChannel = ebi.getChannel();
            EnterpriseBasicInfoHistory enterpriseBasicInfoHistory =
                    dozerBeanMapper.map(ebi, EnterpriseBasicInfoHistory.class);
            enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
            userHistoryId = userBaseInformationHistory.getId();
            dozerBeanMapper.map(requestObject, ebi);
            ebi.setChannel(oldChannel);
            ebi.setMainBusiness(requestObject.getPriBusiness());
            ebi.setGmtModified(LocalDateTime.now());
            ebi.setModifiedBy(operationUserId);
            enterpriseBasicInfoMapper.update(ebi, queryWrapperEBI);
            //2022-11-24新增业态相关及四要素修改记录
            if(requestObject.getFormatId()!=null){
                if (StringUtils.isNotBlank(ebi.getAuthorizedFormats())&&ebi.getAuthorizedFormats().contains(requestObject.getFormatId().toString())) {
                } else {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }
            //四要素修改记录
            FactorsModifyRecord factorsModifyRecord = new FactorsModifyRecord();
            boolean companyfactors = false;
            if(StringUtils.isNotBlank(ebi.getCompanyName())&&!ebi.getCompanyName().equals(enterpriseBasicInfoHistory.getCompanyName())){
                factorsModifyRecord.setOldUserName(enterpriseBasicInfoHistory.getCompanyName());
                factorsModifyRecord.setNewUserName(ebi.getCompanyName());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(ebi.getPapersNo())&&!ebi.getPapersNo().equals(enterpriseBasicInfoHistory.getPapersNo())){
                factorsModifyRecord.setOldPapersNo(enterpriseBasicInfoHistory.getPapersNo());
                factorsModifyRecord.setNewPapersNo(ebi.getPapersNo());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(ebi.getLegalRepresentativeName())&&!ebi.getLegalRepresentativeName().equals(enterpriseBasicInfoHistory.getLegalRepresentativeName())){
                factorsModifyRecord.setOldLegalRepresentativeName(enterpriseBasicInfoHistory.getLegalRepresentativeName());
                factorsModifyRecord.setNewLegalRepresentativeName(ebi.getLegalRepresentativeName());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(ebi.getLrnCertificateNo())&&!ebi.getLrnCertificateNo().equals(enterpriseBasicInfoHistory.getLrnCertificateNo())){
                factorsModifyRecord.setOldLrnCertificateNo(enterpriseBasicInfoHistory.getLrnCertificateNo());
                factorsModifyRecord.setNewLrnCertificateNo(ebi.getLrnCertificateNo());
                companyfactors = true;
            }
            if(companyfactors){
                factorsModifyRecord.setUserId(userId);
                factorsModifyRecord.setUserType(userType);
                factorsModifyRecord.setModifyChannel(channel);
                factorsModifyRecord.setModifyFormat(requestObject.getFormatId());
                factorsModifyRecord.setModifyBy(requestObject.getOperationUserId());
                factorsModifyRecord.setGmtModify(LocalDateTime.now());
                factorsModifyRecord.setAuthorizedFormats(enterpriseBasicInfoHistory.getAuthorizedFormats());
                factorsModifyRecordMapper.insert(factorsModifyRecord);
            }
            // if (!CommUtils.objectIsNull(roleId)) {
            // LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
            // queryWrapperEUI.eq(EnterpriseUserInfo::getEntOperatorId, userId);
            // queryWrapperEUI.orderByDesc(EnterpriseUserInfo::getId);
            // List<EnterpriseUserInfo> EnterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperEUI);
            // if (EnterpriseUserInfos.size() > 0) {
            // UserRoleRelation userRoleRelation = new UserRoleRelation();
            // userRoleRelation.setUserId(EnterpriseUserInfos.get(0).getUserId());
            // userRoleRelation.setRoleId(roleId);
            // userRoleRelation.setChannel(channel);
            // userRoleRelation.setEnterpriseId(userId);
            // userRoleRelation.setGmtCreate(LocalDateTime.now());
            // userRoleRelation.setCreateBy(operationUserId);
            // QueryWrapper<EnterpriseUserRole> queryWrapper = new QueryWrapper<>();
            // queryWrapper.eq("role_id", roleId);
            // if (enterpriseUserRoleMapper.selectCount(queryWrapper) != 1) {
            // throw new BusinessException("该角色不存在", "EB00001");
            // }
            // LambdaQueryWrapper<UserRoleRelation> userRoleRelationQueryWrapper = new LambdaQueryWrapper<>();
            // userRoleRelationQueryWrapper.eq(UserRoleRelation::getUserId,
            // EnterpriseUserInfos.get(0).getUserId());
            // userRoleRelationQueryWrapper.eq(UserRoleRelation::getRoleId, roleId);
            // userRoleRelationQueryWrapper.eq(UserRoleRelation::getEnterpriseId, userId);
            // userRoleRelationQueryWrapper.eq(UserRoleRelation::getChannel, channel);
            // if (userRoleRelationMapper.selectCount(userRoleRelationQueryWrapper) != 0) {
            // throw new BusinessException("该用户已拥有该角色！", "BE00001");
            // }
            // userRoleRelationMapper.insert(userRoleRelation);
            // }
            // }
            // 2020-07-31 Songyf 增加保存法定代表人授权委托书url
            String authorizationbookurl = requestObject.getAuthorizationbookurl();
            if (StringUtils.isNotEmpty(authorizationbookurl)) {
                authorizationbookurlModel.delete(userId, requestObject.getChannel());
                Authorizationbookurl authorization = new Authorizationbookurl();
                authorization.setUserId(userId);
                authorization.setChannel(requestObject.getChannel());
                authorization.setAuthorizationBookUrl(authorizationbookurl);
                authorization.setCreateBy(operationUserId);
                authorization.setGmtCreate(LocalDateTime.now());
                authorization.setModifiedBy(operationUserId);
                authorization.setGmtModified(LocalDateTime.now());
                authorizationbookurlModel.save(authorization);
            }
        }
        LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB =
                new LambdaQueryWrapper<NaturalPersonBaseInformation>();
        queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
        NaturalPersonBaseInformation nbi = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
        // NaturalPersonBaseInformation nbi = naturalPersonBaseInformationMapper.selectById(userId);
        if (nbi == null && SystemConstant.USER_TYPE_2.equals(userType)) {// 没有保存过自然人附属信息表
            naturalPersonBaseInformation.setUserId(userId);
            naturalPersonBaseInformation.setCreateBy(operationUserId);
            naturalPersonBaseInformation.setModifiedBy(operationUserId);
            naturalPersonBaseInformation.setGmtModified(LocalDateTime.now());
            naturalPersonBaseInformationMapper.insert(naturalPersonBaseInformation);
        }
        if (nbi != null && SystemConstant.USER_TYPE_2.equals(userType)) {
            NaturalPersonBaseInformationHistory naturalPersonBaseInformationHistory =
                    dozerBeanMapper.map(nbi, NaturalPersonBaseInformationHistory.class);
            naturalPersonBaseInformationHistory.setId(userHistoryId);
            naturalPersonBaseInformationHistoryMapper.insert(naturalPersonBaseInformationHistory);
            String oldChannel = nbi.getChannel();
            dozerBeanMapper.map(requestObject, nbi);
            nbi.setChannel(oldChannel);
            nbi.setGmtModified(LocalDateTime.now());
            nbi.setModifiedBy(operationUserId);
            naturalPersonBaseInformationMapper.update(nbi, queryWrapperNPB);
            //2022-11-24新增业态相关及四要素修改记录
            if(requestObject.getFormatId()!=null){
                if (StringUtils.isNotBlank(nbi.getAuthorizedFormats())&&nbi.getAuthorizedFormats().contains(requestObject.getFormatId().toString())) {
                } else {
                    throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
                }
            }
            //四要素修改记录
            FactorsModifyRecord factorsModifyRecord = new FactorsModifyRecord();
            boolean companyfactors = false;
            if(StringUtils.isNotBlank(nbi.getUserName())&&!nbi.getUserName().equals(naturalPersonBaseInformationHistory.getUserName())){
                factorsModifyRecord.setOldUserName(naturalPersonBaseInformationHistory.getUserName());
                factorsModifyRecord.setNewUserName(nbi.getUserName());
                companyfactors = true;
            }
            if(StringUtils.isNotBlank(nbi.getPapersNo())&&!nbi.getPapersNo().equals(naturalPersonBaseInformationHistory.getPapersNo())){
                factorsModifyRecord.setOldPapersNo(naturalPersonBaseInformationHistory.getPapersNo());
                factorsModifyRecord.setNewPapersNo(nbi.getPapersNo());
                companyfactors = true;
            }
            if(companyfactors){
                factorsModifyRecord.setUserId(userId);
                factorsModifyRecord.setUserType(userType);
                factorsModifyRecord.setModifyChannel(channel);
                factorsModifyRecord.setModifyFormat(requestObject.getFormatId());
                factorsModifyRecord.setModifyBy(requestObject.getOperationUserId());
                factorsModifyRecord.setGmtModify(LocalDateTime.now());
                factorsModifyRecord.setAuthorizedFormats(naturalPersonBaseInformationHistory.getAuthorizedFormats());
                factorsModifyRecordMapper.insert(factorsModifyRecord);
            }
        }
        // 2021-07-07新增对接客商 syf
        cloudPlatformAsync.authenticationToCloudPlatformCheck(requestObject, userType, oldPapersNo, newPapersNo,
                userId);
        return SystemConstant.SYSTEM_SUCCESS;
    }

    private void dataFormatCheck(NaturalPersonBaseInformation naturalPersonBaseInformation,
                                 EnterpriseBasicInfo enterpriseBasicInfo, UserBaseInformation userBaseInformation) throws BusinessException {
        if (naturalPersonBaseInformation != null
                && StringUtils.isNotEmpty(naturalPersonBaseInformation.getSpouseTelephone())
                && !CommUtils.isPhone(naturalPersonBaseInformation.getSpouseTelephone())) {
            throw new BusinessException("配偶" + SystemConstant.TELEPHONE_FORMAT_ERROR,
                    ErrorMessageConstant.ECUC0019_CODE);
        }

        // if (enterpriseBasicInfo != null && StringUtils.isNotEmpty(enterpriseBasicInfo.getAdminTelephone()) &&
        // !CommUtils.isPhone(enterpriseBasicInfo.getAdminTelephone())) {
        // throw new BusinessException("管理员" + SystemConstant.TELEPHONE_FORMAT_ERROR,
        // ErrorMessageConstant.ECUC0019_CODE);
        // }

        if (enterpriseBasicInfo != null && StringUtils.isNotEmpty(enterpriseBasicInfo.getEmail())
                && !CommUtils.isEmail(enterpriseBasicInfo.getEmail())) {
            throw new BusinessException("企业" + SystemConstant.EMAIL_FORMAT_ERROR, ErrorMessageConstant.ECUC0019_CODE);
        }

        // if (enterpriseBasicInfo != null && StringUtils.isNotEmpty(enterpriseBasicInfo.getAdminEmail()) &&
        // !CommUtils.isEmail(enterpriseBasicInfo.getAdminEmail())) {
        // throw new BusinessException("管理员工" + SystemConstant.EMAIL_FORMAT_ERROR, ErrorMessageConstant.ECUC0019_CODE);
        // }

        if (naturalPersonBaseInformation != null && StringUtils.isNotEmpty(naturalPersonBaseInformation.getEmail())
                && !CommUtils.isEmail(naturalPersonBaseInformation.getEmail())) {
            throw new BusinessException(SystemConstant.EMAIL_FORMAT_ERROR, ErrorMessageConstant.ECUC0019_CODE);
        }
    }
    /* 用户认证 end */

    /*  修改/重置密码维护 begin */

    /**
     * @program: 2019-10-12_userCenter
     * @description: 修改/重置密码维护事务层
     * @author: DaiGaoLe
     * @create: 2019-10-22 16:38
     **/
    @Transactional(rollbackFor = Exception.class)
    public String userPasswordMaintenance(UserPasswordMaintenanceReq requestObject) {
        // 声明变量 begin
        String returnsResult = SystemConstant.SYSTEM_SUCCESS;
        // 用户id
        Integer userId = requestObject.getUserId();
        // String operationUserId = requestObject.getOperationUserId ();
        // 操作类型(0-重置密码，1-修改密码)
        String operationType = requestObject.getOperationType();
        String newLoginPassword = requestObject.getNewLoginPassword();
        String originalLoginPassword = requestObject.getOriginalLoginPassword();
        UserBaseInformation user = this.getById(userId);
        UserBaseInformationHistory userHistory = dozerBeanMapper.map(user, UserBaseInformationHistory.class);
        if (user == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }

        // 声明变量 begin
        if (SystemConstant.UPM_OPERATION_TYPE_1.equals(operationType)) {// 修改密码
            // 密码格式不正确
            if (StringUtils.isNotEmpty(newLoginPassword) && !CommUtils.checkPassword(newLoginPassword)) {
                throw new BusinessException("新密码" + ErrorMessageConstant.ECUC0021_MESSAGE,
                        ErrorMessageConstant.ECUC0021_CODE);
            }

            if (StringUtils.isNotEmpty(newLoginPassword) && StringUtils.isNotEmpty(originalLoginPassword)) {
                String md5SaltPasswordOld = CommUtils.getMd5SaltPassword(originalLoginPassword, user.getSalt());
                if (!md5SaltPasswordOld.equals(user.getUserPassword())) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0022_MESSAGE,
                            ErrorMessageConstant.ECUC0022_CODE);
                }
            } else {
                throw new BusinessException("新旧密码不能为空", ErrorMessageConstant.ECUC0022_CODE);
            }
            user.setUserPassword(CommUtils.getMd5SaltPassword(newLoginPassword, user.getSalt()));
            user.setGmtModified(LocalDateTime.now());
            user.setModifiedBy(requestObject.getOperationUserId());
            this.updateById(user);
        } else if (SystemConstant.UPM_OPERATION_TYPE_0.equals(operationType)) {// 重置密码
            if (StringUtils.isNotEmpty(newLoginPassword) && !CommUtils.checkPassword(newLoginPassword)) {
                throw new BusinessException("重置密码格式不正确", ErrorMessageConstant.ECUC0021_CODE);
            }
            String systemDefaultPassword = commUtils.getSystemParameterValueOne(
                    SystemConstant.SYSTEM_PARAMETERS_CODE_0000000002, SystemConstant.SYSTEM_PARAMETERS_NAME_0000000002);
            if (StringUtils.isNotEmpty(newLoginPassword)) {
                user.setUserPassword(CommUtils.getMd5SaltPassword(newLoginPassword, user.getSalt()));
            } else {
                if (StringUtils.isEmpty(systemDefaultPassword)) {
                    throw new BusinessException(ErrorMessageConstant.ECUC0023_MESSAGE,
                            ErrorMessageConstant.ECUC0023_CODE);
                }
                user.setUserPassword(CommUtils.getMd5SaltPassword(systemDefaultPassword, user.getSalt()));
            }
            user.setGmtModified(LocalDateTime.now());
            user.setModifiedBy(requestObject.getOperationUserId());
            this.updateById(user);
        }
        userBaseInformationHistoryMapper.insert(userHistory);
        String userType = user.getUserType();
        HashSet<String> userName = new HashSet<String>();
        HashSet<String> channelName = new HashSet<String>();
        if (SystemConstant.USER_TYPE_1.equals(userType)) {
            LambdaQueryWrapper<EmployeeInformation> queryWrapper = new LambdaQueryWrapper<EmployeeInformation>();
            queryWrapper.eq(EmployeeInformation::getUserId, userId);
            queryWrapper.eq(EmployeeInformation::getIsDelete, SystemConstant.DELETE_FLAG_0);
            List<EmployeeInformation> employeeInformations = employeeInformationMapper.selectList(queryWrapper);
            if (employeeInformations.size() > 1) {
                for (int i = 0; i < employeeInformations.size(); i++) {
                    userName.add(employeeInformations.get(i).getUserName());
                }
                ztProducer.sendMessagesModifyUserPasswordIn(userId, userName.toString());
            }
            if (employeeInformations.size() > 0) {
                for (int i = 0; i < employeeInformations.size(); i++) {
                    searchAllChannelsReq req = new searchAllChannelsReq();
                    req.setQueryChannel(employeeInformations.get(i).getChannel());
                    channelName.add(channelConfigModel.listAlls(req).get(0).getChannelName());
                    if (SystemConstant.UPM_OPERATION_TYPE_1.equals(operationType)) {
                        returnsResult = "密码修改成功，共用该账号的" + channelName.toString().replace(",", "、") + "密码将同步修改。";
                    } else if (SystemConstant.UPM_OPERATION_TYPE_0.equals(operationType)) {
                        returnsResult = "密码重置成功，共用该账号的" + channelName.toString().replace(",", "、") + "密码将同步重置。";
                    }
                }
            }
        } else if (SystemConstant.USER_TYPE_3.equals(userType)) {
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapper.eq(EnterpriseUserInfo::getUserId, userId);
            queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.DELETE_FLAG_0);
            List<EnterpriseUserInfo> enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapper);
            if (enterpriseUserInfos.size() > 1) {
                for (int i = 0; i < enterpriseUserInfos.size(); i++) {
                    userName.add(enterpriseUserInfos.get(i).getUserName());
                }
                ztProducer.sendMessagesModifyUserPasswordIn(userId, userName.toString());
            }
            if (enterpriseUserInfos.size() > 0) {
                for (int i = 0; i < enterpriseUserInfos.size(); i++) {
                    searchAllChannelsReq req = new searchAllChannelsReq();
                    req.setQueryChannel(enterpriseUserInfos.get(i).getChannel());
                    channelName.add(channelConfigModel.listAlls(req).get(0).getChannelName());
                    returnsResult = channelName.toString();
                    if (SystemConstant.UPM_OPERATION_TYPE_1.equals(operationType)) {
                        returnsResult = "密码修改成功，共用该账号的" + channelName.toString().replace(",", "、") + "密码将同步修改。";
                    } else if (SystemConstant.UPM_OPERATION_TYPE_0.equals(operationType)) {
                        returnsResult = "密码重置成功，共用该账号的" + channelName.toString().replace(",", "、") + "密码将同步重置。";
                    }
                }
            }
        }
        return returnsResult;
    }
    /* 修改/重置密码维护 end */

    /* 档案查看 begin */
    public ViewArchivesDto viewArchives(ViewArchivesReq requestObject) {
        // 声明变量 begin
        Integer userId = requestObject.getUserId();
        String userType = null;
        ViewArchivesDto viewArchivesDto = new ViewArchivesDto();
        UserBaseInformation userBaseInformation = this.getById(userId);
        EnterpriseBasicInfo enterpriseBasicInfo = null;
        NaturalPersonBaseInformation naturalPersonBaseInformation = null;
        EnterpriseUserInfo enterpriseUserInfo = null;
        // 声明变量 end

        if (userBaseInformation == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }
        userType = userBaseInformation.getUserType();
        // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
        if (SystemConstant.USER_TYPE_0.equals(userType)) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            if (enterpriseBasicInfo != null) {
                dozerBeanMapper.map(enterpriseBasicInfo, viewArchivesDto);
                Authorizationbookurl authorizationbookurl =
                        authorizationbookurlModel.searchByUserIdAndChannel(userId, userBaseInformation.getChannel());
                if (authorizationbookurl != null) {
                    viewArchivesDto.setAuthorizationBookUrl(authorizationbookurl.getAuthorizationBookUrl());
                }
            }
        }

        if (SystemConstant.USER_TYPE_3.equals(userType)) {
            // 没数据
            // enterpriseUserInfo = enterpriseUserInfoMapper.selectById(userId);
            // if (enterpriseUserInfo != null) {
            // dozerBeanMapper.map(enterpriseUserInfo, viewArchivesDto);
            // }
        }

        if (SystemConstant.USER_TYPE_2.equals(userType)) {
            naturalPersonBaseInformation = naturalPersonBaseInformationMapper.selectById(userId);
            if (naturalPersonBaseInformation != null) {
                dozerBeanMapper.map(naturalPersonBaseInformation, viewArchivesDto);
            }
        }
        return viewArchivesDto;
    }
    /* 档案查看 end */

    /* 公共方法区 begin */
    private boolean isUserExist(UserRegistrationReq requestObject) {
        QueryWrapper<UserBaseInformation> queryWrapper = new QueryWrapper<>();
        String userName = requestObject.getUserName();
        queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", userName);
        Integer integer = this.getBaseMapper().selectCount(queryWrapper);
        if (integer > 0) {
            return true;
        }
        return false;
    }
    /* 公共方法区 end */

    private List<String> stringToList(String[] value) {
        List<String> resultList = new ArrayList<>(value.length);
        for (String s : value) {
            resultList.add(s);
        }
        return resultList;
    }

    /**
     * 添加企业员工用户
     *
     * @param requestObject
     * @return
     * @throws BusinessException
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer addEnterpriseUserInfo(AddEnterpriseUserInfoReq requestObject) throws BusinessException {
        String channel = requestObject.getChannel();
        String telephone = requestObject.getTelephone();
        String userName = requestObject.getUserName();
        String papersType = requestObject.getPapersType();
        String papersNo = requestObject.getPapersNo();
        String passWord = requestObject.getUserPassword();
        Integer enterpriseId = requestObject.getEnterpriseId();
        // add by gaole.dai 2019-12-31 添加企业员工用户服务增加三要素校验(使用e签宝) begin
        // 若证件类型为身份证则校验，若不为身份证则跳过该校验
        // if (SystemConstant.PAPERS_TYPE_04.equals(requestObject.getPapersType())) {
        // PersonsThreeFactorReq personsThreeFactorReq = new PersonsThreeFactorReq();
        // dozerBeanMapper.map(requestObject, personsThreeFactorReq);
        // personsThreeFactorReq.setIdNo(requestObject.getPapersNo());
        // personsThreeFactorReq.setMobileNo(requestObject.getTelephone());
        // personsThreeFactorReq.setName(requestObject.getUserName());
        // String s = esignApiModel.personsServiceProviderThreeFactorVerification(personsThreeFactorReq);
        // if (StringUtils.isEmpty(s)) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE, ErrorMessageConstant.ECUC0038_CODE);
        // }
        // }
        // add by gaole.dai 2019-12-31 添加企业员工用户服务增加三要素校验(使用e签宝) end
        // 验证企业用户是否存在
        if (!checkRepeatCompanyUser(enterpriseId)) {
            throw new BusinessException("该企业用户不存在或该用户非企业用户，请重新输入！", ErrorMessageConstant.ECUC0002_CODE);
        }
        //验证该手机号是否有其他人使用 2022-04-18
        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperTEL = new LambdaQueryWrapper<EnterpriseUserInfo>();
        queryWrapperTEL.eq(EnterpriseUserInfo::getTelephone, requestObject.getTelephone());
        queryWrapperTEL.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        queryWrapperTEL.ne(EnterpriseUserInfo::getPapersNo, requestObject.getPapersNo());
        if (enterpriseUserInfoMapper.selectCount(queryWrapperTEL) != 0) {
            throw new BusinessException("该手机号已被使用！", ErrorMessageConstant.ECUC0024_CODE);
        }
        // 验证企业员工用户是否已创建
        if (!checkRepeatUser(papersType, papersNo) && !checkRepeatUserTelephone(telephone)) {
            // 验证企业员工用户账号是否已使用
            if (checkRepeatAccountId(requestObject.getUserAccounts())) {
                throw new BusinessException("该企业员工用户账号已使用，请重新输入！", ErrorMessageConstant.ECUC0001_CODE);
            }
        } else {
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapper.eq(EnterpriseUserInfo::getPapersType, papersType);
            queryWrapper.eq(EnterpriseUserInfo::getPapersNo, papersNo);
            queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            List<EnterpriseUserInfo> enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapper);
            if (enterpriseUserInfos.size() == 0) {
                LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperTelephone =
                        new LambdaQueryWrapper<EnterpriseUserInfo>();
                queryWrapperTelephone.eq(EnterpriseUserInfo::getTelephone, telephone);
                queryWrapperTelephone.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperTelephone.orderByDesc(EnterpriseUserInfo::getId);
                enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperTelephone);
            }
            UserBaseInformation user =
                    userBaseInformationMapper.getUserByUserId(enterpriseUserInfos.get(0).getUserId());
            String accounts = user.getUserAccounts();
            if (!accounts.equals(requestObject.getUserAccounts())) {
                throw new BusinessException("账号错误,其它渠道或企业已使用该证件号或手机号注册此用户，若想实现员工复用请修改账号为" + accounts + "重新注册！",
                        ErrorMessageConstant.ECUC0000_CODE);
            }
            if (StringUtils.isNotBlank(passWord)) {
                String md5SaltPassword = CommUtils.getMd5SaltPassword(passWord, user.getSalt());
                if (!user.getUserPassword().equals(md5SaltPassword)) {
                    throw new BusinessException("请与该账户在其它渠道或企业的密码保持一致", ErrorMessageConstant.ECUC0008_CODE);
                }
            }
        }
        // 验证证件类型+证件号+企业id+渠道是否已使用
        if (checkRepeatUserByChannel(papersType, papersNo, channel, enterpriseId)) {
            throw new BusinessException("该企业员工证件信息已使用，请重新输入！", ErrorMessageConstant.ECUC0001_CODE);
        }
        // 验证员工用户名称+手机号+企业id+渠道是否已使用
        if (checkRepeatUserNameAndPhone(userName, telephone, channel, enterpriseId)) {
            throw new BusinessException("手机号在当前渠道和企业已存在", ErrorMessageConstant.ECUC0024_CODE);
        }
        // 验证企业员工用户是否已创建
        if (checkRepeatUser(papersType, papersNo) || checkRepeatUserTelephone(telephone)) {
            LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
            queryWrapper.eq(EnterpriseUserInfo::getPapersType, papersType);
            queryWrapper.eq(EnterpriseUserInfo::getPapersNo, papersNo);
            queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            List<EnterpriseUserInfo> enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapper);
            if (enterpriseUserInfos.size() == 0) {
                LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperTelephone =
                        new LambdaQueryWrapper<EnterpriseUserInfo>();
                queryWrapperTelephone.eq(EnterpriseUserInfo::getTelephone, telephone);
                queryWrapperTelephone.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
                queryWrapperTelephone.orderByDesc(EnterpriseUserInfo::getId);
                enterpriseUserInfos = enterpriseUserInfoMapper.selectList(queryWrapperTelephone);
            }
            Integer userId = enterpriseUserInfos.get(0).getUserId();
            EnterpriseUserInfo enterpriseUserInfo1 = dozerBeanMapper.map(requestObject, EnterpriseUserInfo.class);
            enterpriseUserInfo1.setUserId(userId);
            enterpriseUserInfo1.setEntOperatorId(enterpriseId);
            enterpriseUserInfo1.setModifiedBy(requestObject.getOperationUserId());
            enterpriseUserInfo1.setCreateBy(requestObject.getOperationUserId());
            enterpriseUserInfo1.setGmtCreate(LocalDateTime.now());
            enterpriseUserInfo1.setGmtModified(LocalDateTime.now());
            enterpriseUserInfo1.setChannel(channel);
            enterpriseUserInfoMapper.insert(enterpriseUserInfo1);

            // add by liwq on 2021-07-05 start
            // 将数据同步到云平台
            cloudPlatformAsync.mergeDataToCloudPlatform(requestObject, userId);
            // add by liwq on 2021-07-05 end

            return userId;
        } else {
            // 验证手机号是否被使用
            // if (checkRepeatTelephone(requestObject.getTelephone(), requestObject.getChannel())) {
            // throw new BusinessException("该企业员工用户手机号已被使用，请重新输入！", ErrorMessageConstant.ECUC0024_CODE);
            // }
            // 验证该企业是否已存在该员工
            // if
            // (checkCompanyHaveRepeatUser(requestObject.getPapersType(),requestObject.getPapersNo(),requestObject.getOperationUserId()))
            // {
            // throw new BusinessException("该企业员工在该企业已存在账户！", ErrorMessageConstant.ECUC0025_CODE);
            // }
            //账号非中文校验
            Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
            Matcher m = p.matcher(requestObject.getUserAccounts());
            if (m.find()) {
                throw new BusinessException("userAccounts不能是中文", ErrorMessageConstant.ECUC0057_CODE);
            }
            // 密码强度校验
            if (StringUtils.isNotEmpty(requestObject.getUserPassword())
                    && !CommUtils.checkPassword(requestObject.getUserPassword())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0021_MESSAGE, ErrorMessageConstant.ECUC0021_CODE);
            }
            // 邮箱校验
            if (requestObject.getEmail() != null && !CommUtils.isEmail(requestObject.getEmail())) {
                throw new BusinessException("邮箱格式不正确", ErrorMessageConstant.ECUC0016_CODE);
            }
            // 验证通过，添加企业员工用户
            UserBaseInformation userBaseInformation = dozerBeanMapper.map(requestObject, UserBaseInformation.class);
            userBaseInformation.setUserType(SystemConstant.USER_TYPE_3);
            userBaseInformation.setSalt(CommUtils.getSalt());
            if (StringUtils.isBlank(passWord)) {
                throw new BusinessException("密码不可为空", ErrorMessageConstant.ECUC0007_CODE);
            }
            // 密码进行加盐MD5加密
            userBaseInformation.setUserPassword(CommUtils.getMd5SaltPassword(passWord, userBaseInformation.getSalt()));
            // add by gaole.dai 2019-12-17 添加创建人，修改人，和修改时间 begin
            userBaseInformation.setModifiedBy(requestObject.getOperationUserId());
            userBaseInformation.setCreateBy(requestObject.getOperationUserId());
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setBusinessSeqNo(requestObject.getTraceId());
            // add by gaole.dai 2019-12-17 添加创建人，修改人，和修改时间 end
            boolean saveUserBaseInformation = this.save(userBaseInformation);
            EnterpriseUserInfo enterpriseUserInfo1 = dozerBeanMapper.map(requestObject, EnterpriseUserInfo.class);
            enterpriseUserInfo1.setUserId(userBaseInformation.getUserId());
            enterpriseUserInfo1.setEntOperatorId(enterpriseId);
            enterpriseUserInfo1.setModifiedBy(requestObject.getOperationUserId());
            enterpriseUserInfo1.setCreateBy(requestObject.getOperationUserId());
            enterpriseUserInfo1.setGmtCreate(LocalDateTime.now());
            enterpriseUserInfo1.setGmtModified(LocalDateTime.now());
            enterpriseUserInfo1.setChannel(channel);
            int insert = enterpriseUserInfoMapper.insert(enterpriseUserInfo1);
            if (saveUserBaseInformation && insert == 1) {

                // add by liwq on 2021-07-05 start
                // 将数据同步到云平台
                cloudPlatformAsync.mergeDataToCloudPlatform(requestObject, userBaseInformation.getUserId());
                // add by liwq on 2021-07-05 end

                return enterpriseUserInfo1.getUserId();
            } else {
                throw new BusinessException("添加企业员工用户信息失败", "BE00001");
            }

        }
    }

    /**
     * 判断用户名称+手机号+企业id+渠道是否存在
     *
     * @param userName,telephone
     * @return boolean
     * @author: Songyf
     */

    public boolean checkRepeatUserNameAndPhone(String userName, String telephone, String channel, int enterpriseId) {

        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
        // queryWrapper.eq(EnterpriseUserInfo::getUserName, userName);
        queryWrapper.eq(EnterpriseUserInfo::getTelephone, telephone);
        queryWrapper.eq(EnterpriseUserInfo::getChannel, channel);
        queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        queryWrapper.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
        return 0 != enterpriseUserInfoMapper.selectCount(queryWrapper);
    }

    /**
     * 查询企业员工用户是否已添加
     *
     * @param papersType,papersNo
     * @return boolean
     * @author: Songyf
     */
    public boolean checkRepeatUserByChannel(String papersType, String papersNo, String channel, int enterpriseId) {
        // 身份证号有效性校验
        if (SystemConstant.PAPERS_TYPE_04.equals(papersType) && !CommUtils.isIdNumber(papersNo)) {
            throw new BusinessException("请输入正确的身份证信息！", "BE00001");
        }
        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
        queryWrapper.eq(EnterpriseUserInfo::getPapersType, papersType);
        queryWrapper.eq(EnterpriseUserInfo::getPapersNo, papersNo);
        queryWrapper.eq(EnterpriseUserInfo::getChannel, channel);
        queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        queryWrapper.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
        Integer selectCount = enterpriseUserInfoMapper.selectCount(queryWrapper);
        return selectCount != 0;
    }

    /**
     * 根据渠道、企业id、用户id获取信息
     *
     * @param channel,userId,enterpriseId
     * @return EnterpriseUserInfo
     * @author: Songyf
     */
    public EnterpriseUserInfo getEnterpriseUserInfo(String channel, Integer userId, Integer enterpriseId) {
        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
        queryWrapper.eq(EnterpriseUserInfo::getChannel, channel);
        queryWrapper.eq(EnterpriseUserInfo::getUserId, userId);
        queryWrapper.eq(EnterpriseUserInfo::getEntOperatorId, enterpriseId);
        queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        EnterpriseUserInfo enterpriseUserInfo = enterpriseUserInfoMapper.selectOne(queryWrapper);
        if (enterpriseUserInfo == null) {
            throw new BusinessException("用户" + userId + "不存在！", ErrorMessageConstant.ECUC0001_CODE);
        }
        return enterpriseUserInfo;
    }

    /**
     * 判断员工用户账号是否存在
     *
     * @param accountId
     * @return boolean
     * @author: Wangxz
     */

    public boolean checkRepeatAccountId(String accountId) {
        queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_accounts", accountId);
        queryWrapper.eq("is_delete", SystemConstant.IS_DELETE_0);
        List<UserBaseInformation> userBaseInformations = userBaseInformationMapper.selectList(queryWrapper);
        if (userBaseInformations.size() > 0) {
            return true;
        } else {
            return false;
            // LambdaQueryWrapper<EnterpriseUserInfo> queryWrapperEUI = new LambdaQueryWrapper<EnterpriseUserInfo>();
            // queryWrapperEUI.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
            // queryWrapperEUI.eq(EnterpriseUserInfo::getUserId, userBaseInformation.getUserId());
            // return (0 != enterpriseUserInfoMapper.selectCount(queryWrapperEUI));
        }
    }

    /**
     * 根据用户编号判断该企业用户是否存在
     *
     * @param enterpriseId
     * @return boolean
     * @author: Wangxz
     */

    public boolean checkRepeatCompanyUser(Integer enterpriseId) {
        // queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("user_id", userId);
        // Integer entOperatorId = enterpriseUserInfoMapper.getEnterpriseUserInfo(userId).getEntOperatorId();
        // List<String> channel = new ArrayList<>();
        // channel.add("T01");
        // queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("user_id", enterpriseId);
        // queryWrapper.eq("user_type", SystemConstant.USER_TYPE_0);
        // queryWrapper.in("channel", channel);
        // queryWrapper.("select");
        // Count函数返回查询条数
        // return 0 != userBaseInformationMapper.getUserByUserId(enterpriseId,SystemConstant.USER_TYPE_0);
        UserBaseInformation userBaseInformation =
                userBaseInformationMapper.getUserByUserIdAndType(enterpriseId, SystemConstant.USER_TYPE_0);
        if (userBaseInformation == null) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 查询手机号是否重复
     *
     * @param telephone,channel
     * @return boolean
     * @author: Wangxz
     */

    public boolean checkRepeatTelephone(String telephone, String channel) {
        if (!CommUtils.isPhone(telephone)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }
        queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("telephone", telephone);
        queryWrapper.eq("channel", channel);
        queryWrapper.eq("user_type", SystemConstant.USER_TYPE_3);
        return 0 != userBaseInformationMapper.selectCount(queryWrapper);
    }

    /**
     * 查询企业员工用户是否已添加
     *
     * @param papersType,papersNo
     * @return boolean
     * @author: Wangxz
     */

    public boolean checkRepeatUser(String papersType, String papersNo) {
        // 身份证号有效性校验
        if (SystemConstant.PAPERS_TYPE_04.equals(papersType) && !CommUtils.isIdNumber(papersNo)) {
            throw new BusinessException("请输入正确的身份证信息！", "BE00001");
        }
        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
        queryWrapper.eq(EnterpriseUserInfo::getPapersType, papersType);
        queryWrapper.eq(EnterpriseUserInfo::getPapersNo, papersNo);
        queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        Integer selectCount = enterpriseUserInfoMapper.selectCount(queryWrapper);
        return selectCount != 0;
    }

    public boolean checkRepeatUserTelephone(String telephone) {
        LambdaQueryWrapper<EnterpriseUserInfo> queryWrapper = new LambdaQueryWrapper<EnterpriseUserInfo>();
        queryWrapper.eq(EnterpriseUserInfo::getTelephone, telephone);
        queryWrapper.eq(EnterpriseUserInfo::getIsDelete, SystemConstant.IS_DELETE_0);
        Integer selectCount = enterpriseUserInfoMapper.selectCount(queryWrapper);
        return selectCount != 0;
    }

    /**
     * 渠道用户授权
     *
     * @return boolean
     * @author: Wangxz
     */
    @Transactional(rollbackFor = Exception.class)
    public String channelUserAuthorization(ChannelUserAuthorizationReq requestObj) {
        // 声明变量 begin
        Integer userId = requestObj.getUserId();
        Integer operationUserId = requestObj.getOperationUserId();
        String channel = requestObj.getChannel();
        String result = SystemConstant.SYSTEM_SUCCESS;
        // 声明变量 end
        UserBaseInformation userBaseInformation = this.baseMapper.selectById(userId);
        if (userBaseInformation == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }
        if (!(SystemConstant.USER_TYPE_0.equals(userBaseInformation.getUserType())||SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType()))) {
            throw new BusinessException(ErrorMessageConstant.ECUC0058_MESSAGE, ErrorMessageConstant.ECUC0058_CODE);
        }
        if(StringUtils.isNotBlank(requestObj.getUserType())){
            if(!userBaseInformation.getUserType().equals(requestObj.getUserType())){
                throw new BusinessException(ErrorMessageConstant.ECUC0070_MESSAGE, ErrorMessageConstant.ECUC0070_CODE);
            }
        }
        // add by gaole.dai 2019-12-31 添加邀请制渠道，授权用户是否是被邀请的用户了 begin
        // QueryWrapper<SystemParameters> queryWrapperSp0 = new QueryWrapper<>();
        // queryWrapperSp0.eq(SystemConstant.SYSTEM_PARAMETERS_CODE, SystemConstant.SYSTEM_PARAMETERS_CODE_0000000004);
        // queryWrapperSp0.eq(SystemConstant.SYSTEM_PARAMETERS_NAME, SystemConstant.SYSTEM_PARAMETERS_NAME_0000000004);
        // List<SystemParameters> systemParameters0 = systemParametersMapper.selectList(queryWrapperSp0);
        //
        // if (systemParameters0 == null || systemParameters0.size() == 0) {
        // throw new BusinessException("系统参数没有配置",ErrorMessageConstant.ECUC0000_CODE);
        // }
        //
        // if (systemParameters0.size() > 1) {
        // throw new BusinessException("系统参数配置异常",ErrorMessageConstant.ECUC0000_CODE);
        // }
        //
        // SystemParameters systemParameter0 = systemParameters0.get(0);
        // // 如果是邀请制渠道
        // if(systemParameter0.getValue().contains(channel)){
        // String enteredInviteCode = userBaseInformation.getEnteredInviteCode();
        // if (StringUtils.isEmpty(enteredInviteCode)) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0038_MESSAGE,ErrorMessageConstant.ECUC0038_CODE);
        // }
        // }
        // add by gaole.dai 2019-12-31 添加邀请制渠道，授权用户是否是被邀请的用户了 end
        if(SystemConstant.USER_TYPE_0.equals(userBaseInformation.getUserType())) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            String authorizedChannels = enterpriseBasicInfo.getAuthorizedChannels();

            if (StringUtils.isNotEmpty(authorizedChannels) && !authorizedChannels.contains(channel)) {
                enterpriseBasicInfo.setAuthorizedChannels(authorizedChannels + "," + channel);
            } else {
                if (StringUtils.isNotEmpty(authorizedChannels) && authorizedChannels.contains(channel)) {
                    throw new BusinessException("用户已经授权");
                }
                enterpriseBasicInfo.setAuthorizedChannels(channel);
            }
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setModifiedBy(operationUserId);
            this.baseMapper.updateById(userBaseInformation);
            enterpriseBasicInfo.setGmtModified(LocalDateTime.now());
            enterpriseBasicInfo.setModifiedBy(operationUserId);
            enterpriseBasicInfoMapper.update(enterpriseBasicInfo, queryWrapperEBI);
        }else if(SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType())) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNPB = new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNPB.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation naturalPersonBaseInformation = naturalPersonBaseInformationMapper.selectOne(queryWrapperNPB);
            String authorizedChannels = naturalPersonBaseInformation.getAuthorizedChannels();

            if (StringUtils.isNotEmpty(authorizedChannels) && !authorizedChannels.contains(channel)) {
                naturalPersonBaseInformation.setAuthorizedChannels(authorizedChannels + "," + channel);
            } else {
                if (StringUtils.isNotEmpty(authorizedChannels) && authorizedChannels.contains(channel)) {
                    throw new BusinessException("用户已经授权");
                }
                naturalPersonBaseInformation.setAuthorizedChannels(channel);
            }
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setModifiedBy(operationUserId);
            this.baseMapper.updateById(userBaseInformation);
            naturalPersonBaseInformation.setGmtModified(LocalDateTime.now());
            naturalPersonBaseInformation.setModifiedBy(operationUserId);
            naturalPersonBaseInformationMapper.update(naturalPersonBaseInformation, queryWrapperNPB);
        }
        return result;
    }

    /**
     * 业态授权
     *
     * @param requestObj
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String formatUserAuthorization(FormatUserAuthorizationReq requestObj) {
        // 声明变量 begin
        Integer userId = requestObj.getUserId();
        Integer operationUserId = requestObj.getOperationUserId();
        String channel = requestObj.getChannel();
        String result = SystemConstant.SYSTEM_SUCCESS;
        String formatId = requestObj.getFormatId().toString();
        if (!organizationManagementModel.checkFormatId(requestObj.getFormatId(), channel)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0067_MESSAGE, ErrorMessageConstant.ECUC0067_CODE);
        }
        // 声明变量 end
        UserBaseInformation userBaseInformation = this.baseMapper.selectById(userId);
        if (userBaseInformation == null) {
            throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
        }
        if (!(SystemConstant.USER_TYPE_0.equals(userBaseInformation.getUserType()) || SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType()))) {
            throw new BusinessException("该用户不是企业客户或自然人客户", ErrorMessageConstant.ECUC0058_CODE);
        }
        if (SystemConstant.USER_TYPE_0.equals(userBaseInformation.getUserType())) {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            queryWrapperEBI.orderByDesc(EnterpriseBasicInfo::getGmtModified);
            List<EnterpriseBasicInfo> enterpriseBasicLists = enterpriseBasicInfoMapper.selectList(queryWrapperEBI);
            EnterpriseBasicInfo enterpriseBasicInfo = new EnterpriseBasicInfo();
            if (enterpriseBasicLists.size() > 0) {
                enterpriseBasicInfo = enterpriseBasicLists.get(0);
            } else {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            EnterpriseBasicInfoHistory enterpriseBasicInfoHistory =
                    dozerBeanMapper.map(enterpriseBasicInfo, EnterpriseBasicInfoHistory.class);
            enterpriseBasicInfoHistoryMapper.insert(enterpriseBasicInfoHistory);
            String formatIds = enterpriseBasicInfo.getAuthorizedFormats();

            if (StringUtils.isNotEmpty(formatIds) && !formatIds.contains(formatId)) {
                enterpriseBasicInfo.setAuthorizedFormats(formatIds + "," + formatId);
            } else {
                if (StringUtils.isNotEmpty(formatIds) && formatIds.contains(formatId)) {
                    throw new BusinessException("用户已经授权");
                }
                enterpriseBasicInfo.setAuthorizedFormats(formatId);
            }
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setModifiedBy(operationUserId);
            this.baseMapper.updateById(userBaseInformation);
            enterpriseBasicInfo.setGmtModified(LocalDateTime.now());
            enterpriseBasicInfo.setModifiedBy(operationUserId);
            enterpriseBasicInfoMapper.update(enterpriseBasicInfo, queryWrapperEBI);
        } else if (SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType())) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperEBI = new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperEBI.eq(NaturalPersonBaseInformation::getUserId, userId);
            queryWrapperEBI.orderByDesc(NaturalPersonBaseInformation::getGmtModified);
            List<NaturalPersonBaseInformation> naturalPersonInfoLists = naturalPersonBaseInformationMapper.selectList(queryWrapperEBI);
            NaturalPersonBaseInformation naturalPersonInfo = new NaturalPersonBaseInformation();
            if (naturalPersonInfoLists.size() > 0) {
                naturalPersonInfo = naturalPersonInfoLists.get(0);
            } else {
                throw new BusinessException(ErrorMessageConstant.ECUC0002_MESSAGE, ErrorMessageConstant.ECUC0002_CODE);
            }
            UserBaseInformationHistory userBaseInformationHistory =
                    dozerBeanMapper.map(userBaseInformation, UserBaseInformationHistory.class);
            userBaseInformationHistoryMapper.insert(userBaseInformationHistory);
            Integer userHistoryId = userBaseInformationHistory.getId();
            NaturalPersonBaseInformationHistory naturalPersonBaseInformationHistory =
                    dozerBeanMapper.map(naturalPersonInfo, NaturalPersonBaseInformationHistory.class);
            naturalPersonBaseInformationHistory.setId(userHistoryId);
            naturalPersonBaseInformationHistoryMapper.insert(naturalPersonBaseInformationHistory);
            String formatIds = naturalPersonInfo.getAuthorizedFormats();

            if (StringUtils.isNotEmpty(formatIds) && !formatIds.contains(formatId)) {
                naturalPersonInfo.setAuthorizedFormats(formatIds + "," + formatId);
            } else {
                if (StringUtils.isNotEmpty(formatIds) && formatIds.contains(formatId)) {
                    throw new BusinessException("用户已经授权");
                }
                naturalPersonInfo.setAuthorizedFormats(formatId);
            }
            userBaseInformation.setGmtModified(LocalDateTime.now());
            userBaseInformation.setModifiedBy(operationUserId);
            this.baseMapper.updateById(userBaseInformation);
            naturalPersonInfo.setGmtModified(LocalDateTime.now());
            naturalPersonInfo.setModifiedBy(operationUserId);
            naturalPersonBaseInformationMapper.update(naturalPersonInfo, queryWrapperEBI);
        }
        return result;
    }

    public List<EnterpriseListInfoDto> pursuantTelephoneGetUserName(TelephoneGetUserNameReq requestObj) {
        // 声明变量 begin
        String telephone = requestObj.getTelephone();
        String userAccounts = requestObj.getUserAccounts();
        if (StringUtils.isBlank(telephone) && StringUtils.isBlank(userAccounts)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0061_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }
        if (StringUtils.isNotBlank(telephone) && !CommUtils.isPhone(telephone)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE, ErrorMessageConstant.ECUC0019_CODE);
        }
        String channel = requestObj.getChannel();
        // List<String> result = new ArrayList<>();
        // QueryWrapper<UserBaseInformation> queryWrapper = new QueryWrapper<>();
        // // 声明变量 end
        //
        // queryWrapper.eq("telephone", telephone);
        // queryWrapper.eq("channel", channel);
        // queryWrapper.in("user_type", SystemConstant.USER_TYPE_0, SystemConstant.USER_TYPE_3);
        //
        // List<UserBaseInformation> userBaseInformations = this.getBaseMapper().selectList(queryWrapper);
        // userBaseInformations.forEach(ojb -> {
        // result.add(ojb.getUserName());
        // });
        List<EnterpriseListInfoDto> companyNames = enterpriseUserInfoMapper
                .pursuantTelephoneGetUserName(requestObj.getSearchAllChannels(), telephone, userAccounts, channel);
        return companyNames;
    }

    private void authenticationCheck(UserAuthentication requestObject, UserBaseInformation ubi) {
        String userType = ubi.getUserType();
        String channel = requestObject.getChannel();
        String email = requestObject.getEmail();
        String certificateType = requestObject.getCertificateType();

        String legalRepresentativeName = requestObject.getLegalRepresentativeName();
        String lrnCertificateType = requestObject.getLrnCertificateType();
        String lrnCertificateNo = requestObject.getLrnCertificateNo();
        // String adminName = requestObject.getAdminName();
        // String adminTelephone = requestObject.getAdminTelephone();
        // String adminCertificateType = requestObject.getAdminCertificateType();
        // String adminCertificateNo = requestObject.getAdminCertificateNo();
        // String adminMail = requestObject.getAdminMail();
        String businessLicenseUrl = requestObject.getBusinessLicenseUrl();
        String lrnLicenseUrl = requestObject.getLrnLicenseUrl();
        // String adminLicenseUrl = requestObject.getAdminLicenseUrl();
        String entRegeditAddress = requestObject.getEntRegeditAddress();
        String businessAddress = requestObject.getBusinessAddress();
        String bankAccount = requestObject.getBankAccount();

        String accountName = requestObject.getAccountName();
        String openBank = requestObject.getOpenBank();
        String openAccountProvince = requestObject.getOpenAccountProvince();
        String openingAccountCity = requestObject.getOpeningAccountCity();
        String openBranch = requestObject.getOpenBranch();
        String fixedTelephone = requestObject.getFixedTelephone();
        String accountOpenPermitUrl = requestObject.getAccountOpenPermitUrl();

        String bankAccountInfoCertUrl = requestObject.getBankAccountInfoCertUrl();
        String enterpriseBillingInformationUrl = requestObject.getEnterpriseBillingInformationUrl();
        String enterpriseType = requestObject.getEnterpriseType();

        String businessConditions = requestObject.getBusinessConditions();
        String mainBusiness = requestObject.getMainBusiness();
        String internationalIndustryClass = requestObject.getInternationalIndustryClass();
        String userCreditAmount = requestObject.getUserCreditAmount();
        String gender = requestObject.getGender();
        String workingYears = requestObject.getWorkingYears();
        String unitAddress = requestObject.getUnitAddress();
        String entityName = requestObject.getEntityName();
        String unitNature = requestObject.getUnitNature();
        BigDecimal personalAnnualIncome = requestObject.getPersonalAnnualIncome();
        String personalIdentificationUrl = requestObject.getPersonalIdentificationUrl();
        Date payDay = requestObject.getPayDay();
        String maritalStatus = requestObject.getMaritalStatus();
        String homeAddress = requestObject.getHomeAddress();
        String livingConditions = requestObject.getLivingConditions();
        String nation = requestObject.getNation();
        String spouseName = requestObject.getSpouseName();
        String spouseCertificateType = requestObject.getSpouseCertificateType();
        String spouseCertificateNo = requestObject.getSpouseCertificateNo();
        String spouseTelephone = requestObject.getSpouseTelephone();
        String incomeSource = requestObject.getIncomeSource();
        String bankCardInfoUrl = requestObject.getBankCardInfoUrl();
        String bankOpenBank = requestObject.getBankOpenBank();
        String certificatesforType = requestObject.getCertificatesforType();
        String occupation = requestObject.getOccupation();
        String userName = requestObject.getUserName();
        String papersType = requestObject.getPapersType();
        String papersNo = requestObject.getPapersNo();
        String traceId = requestObject.getTraceId();
        Integer operationUserId = requestObject.getOperationUserId();
        Date requestTime = requestObject.getRequestTime();
        // LocalDate cerSdate = requestObject.getCerSdate();
        // LocalDate cerEdate = requestObject.getCerEdate();
        String registeMoney = requestObject.getRegisteMoney();
        String corpMode = requestObject.getCorpMode();
        String employeeAmount = requestObject.getEmployeeAmount();
        String lastYearTurnover = requestObject.getLastYearTurnover();

        /**
         * ①小贷-企业用户 ②小贷-企业分配人员 ③小贷-个人用户 ④保理-企业用户 ⑤保理-企业分配人员 ⑪保理-个人用户 ⑥青港易付-成员单位 ⑦青港易付-供应商 ⑧青港易付-企业分配人员 ⑨信贷-企业用户
         * ⑩信贷-企业分配人员
         *
         * 法定代表人姓名、法定代表人证件类型、法定代表人证件号码、 管理员姓名、管理员手机号码、证件类型、证件号码、管理员邮箱、营业执照（影像资料）、
         * 法定代表人代表证照（影像资料）、管理员证照（影像资料）、法定代表人授权委托书（影像资料） ①④⑥⑦⑨都必须上送
         *
         */

        if (SystemConstant.CHANNEL_C01.equals(channel)) {// C01-小袋
            // 因为渠道已经做了必输校验，用户类型在注册的时候已经生成了

            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_0.equals(userType) || SystemConstant.USER_TYPE_3.equals(userType)) {
                if (StringUtils.isEmpty(userName)) {
                    throw new BusinessException("用户名不能为空");
                }
                if (StringUtils.isEmpty(certificateType)) {
                    throw new BusinessException("证书类型不能为空");
                }
                if (StringUtils.isEmpty(legalRepresentativeName)) {
                    throw new BusinessException("法定代表人姓名不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateType)) {
                    throw new BusinessException("法定代表人证件类型不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateNo)) {
                    throw new BusinessException("法定代表人证件号码不能为空");
                }

                // if (StringUtils.isEmpty(adminName)) {
                // throw new BusinessException("管理员姓名不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminTelephone)) {
                // throw new BusinessException("管理员手机账号不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateType)) {
                // throw new BusinessException("管理员证件类型不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateNo)) {
                // throw new BusinessException("管理员证件号码不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminMail)) {
                // throw new BusinessException("管理员邮箱不能为空");
                // }

                if (StringUtils.isEmpty(businessLicenseUrl)) {
                    throw new BusinessException("营业执照（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(lrnLicenseUrl)) {
                    throw new BusinessException("法定代表人代表证照（影像资料）不能为空");
                }
                // if (StringUtils.isEmpty(adminLicenseUrl)) {
                // throw new BusinessException("管理员证照（影像资料）不能为空");
                // }

                if (StringUtils.isEmpty(papersType)) {
                    throw new BusinessException("证件类型不能为空");
                }

                if (StringUtils.isEmpty(papersNo)) {
                    throw new BusinessException("证件编号不能为空");
                }

                // if (cerSdate == null) {
                // throw new BusinessException("营业执照有效期开始日期不能为空");
                // }
                //
                // if (cerEdate == null) {
                // throw new BusinessException("营业执照有效期结束日期不能为空");
                // }

                if (StringUtils.isEmpty(entRegeditAddress)) {
                    throw new BusinessException("企业注册地址不能为空");
                }

                if (StringUtils.isEmpty(businessAddress)) {
                    throw new BusinessException("经营地址不能为空");
                }

                if (StringUtils.isEmpty(bankAccount)) {
                    throw new BusinessException("银行账号不能为空");
                }

                if (StringUtils.isEmpty(accountName)) {
                    throw new BusinessException("账户名称不能为空");
                }

                if (StringUtils.isEmpty(openBank)) {
                    throw new BusinessException("开户行不能为空");
                }

                if (StringUtils.isEmpty(openAccountProvince)) {
                    throw new BusinessException("开户省不能为空");
                }

                if (StringUtils.isEmpty(openingAccountCity)) {
                    throw new BusinessException("开户市不能为空");
                }

                if (StringUtils.isEmpty(openBranch)) {
                    throw new BusinessException("开户网点不能为空");
                }

                if (StringUtils.isEmpty(fixedTelephone)) {
                    throw new BusinessException("固定电电话不能为空");
                }

                if (StringUtils.isEmpty(accountOpenPermitUrl)) {
                    throw new BusinessException("开户许可证（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(bankAccountInfoCertUrl)) {
                    throw new BusinessException("银行账户信息证明（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(enterpriseBillingInformationUrl)) {
                    throw new BusinessException("企业开票信息（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(registeMoney)) {
                    throw new BusinessException("注册资金不能为空");
                }

                if (StringUtils.isEmpty(corpMode)) {
                    throw new BusinessException("企业性质不能为空");
                }
                if (StringUtils.isEmpty(employeeAmount)) {
                    throw new BusinessException("员工人数不能为空");
                }

                if (StringUtils.isEmpty(lastYearTurnover)) {
                    throw new BusinessException("上年度营业额不能为空");
                }
            }

            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_2.equals(userType)) {
                if (StringUtils.isEmpty(bankAccount)) {
                    throw new BusinessException("银行账号不能为空");
                }

                if (StringUtils.isEmpty(bankOpenBank)) {
                    throw new BusinessException("银行开户行不能为空");
                }

                if (StringUtils.isEmpty(occupation)) {
                    throw new BusinessException("职业不能为空");
                }

                if (StringUtils.isEmpty(gender)) {
                    throw new BusinessException("民族不能为空");
                }

                if (StringUtils.isEmpty(nation)) {
                    throw new BusinessException("性别不能为空");
                }

                if (StringUtils.isEmpty(livingConditions)) {
                    throw new BusinessException("居住状况不能为空");
                }

                if (StringUtils.isEmpty(homeAddress)) {
                    throw new BusinessException("家庭住址不能为空");
                }

                if (personalAnnualIncome == null) {
                    throw new BusinessException("个人年收入");
                }

                if (StringUtils.isEmpty(incomeSource)) {
                    throw new BusinessException("收入来源不能为空");
                }

                if (StringUtils.isEmpty(entityName)) {
                    throw new BusinessException("单位名称不能为空");
                }

                if (StringUtils.isEmpty(unitNature)) {
                    throw new BusinessException("单位性质不能为空");
                }

                if (StringUtils.isEmpty(workingYears)) {
                    throw new BusinessException("本单位工作年限不能为空");
                }

                if (payDay == null) {
                    throw new BusinessException("工资发放日不能为空");
                }
                if (StringUtils.isEmpty(unitAddress)) {
                    throw new BusinessException("单位地址不能为空");
                }

                if (StringUtils.isEmpty(personalIdentificationUrl)) {
                    throw new BusinessException("个人身份证明（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(bankCardInfoUrl)) {
                    throw new BusinessException("银行卡信息（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(maritalStatus)) {
                    throw new BusinessException("婚姻状况不能为空");
                }
                if (SystemConstant.MARITAL_STATUS_0.equals(maritalStatus)) {// 已婚
                    if (StringUtils.isEmpty(spouseName)) {
                        throw new BusinessException("配偶姓名不能为空");
                    }

                    if (StringUtils.isEmpty(spouseCertificateType)) {
                        throw new BusinessException("证件类型不能为空");
                    }
                    if (StringUtils.isEmpty(spouseCertificateNo)) {
                        throw new BusinessException("证件号码不能为空");
                    }
                    if (StringUtils.isEmpty(spouseTelephone)) {
                        throw new BusinessException("手机号码不能为空");
                    }
                    if (!CommUtils.isPhone(spouseTelephone)) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE,
                                ErrorMessageConstant.ECUC0019_CODE);
                    }
                }
            }

        } else if (SystemConstant.CHANNEL_C02.equals(channel)) {// C02-保理
            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_0.equals(userType) || SystemConstant.USER_TYPE_3.equals(userType)) {
                if (StringUtils.isEmpty(userName)) {
                    throw new BusinessException("用户名不能为空");
                }
                if (StringUtils.isEmpty(certificateType)) {
                    throw new BusinessException("证书类型不能为空");
                }

                if (StringUtils.isEmpty(legalRepresentativeName)) {
                    throw new BusinessException("法定代表人姓名不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateType)) {
                    throw new BusinessException("法定代表人证件类型不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateNo)) {
                    throw new BusinessException("法定代表人证件号码不能为空");
                }

                // if (StringUtils.isEmpty(adminName)) {
                // throw new BusinessException("管理员姓名不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminTelephone)) {
                // throw new BusinessException("管理员手机账号不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateType)) {
                // throw new BusinessException("管理员证件类型不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateNo)) {
                // throw new BusinessException("管理员证件号码不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminMail)) {
                // throw new BusinessException("管理员邮箱不能为空");
                // }

                if (StringUtils.isEmpty(businessLicenseUrl)) {
                    throw new BusinessException("营业执照（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(lrnLicenseUrl)) {
                    throw new BusinessException("法定代表人代表证照（影像资料）不能为空");
                }
                // if (StringUtils.isEmpty(adminLicenseUrl)) {
                // throw new BusinessException("管理员证照（影像资料）不能为空");
                // }

                if (StringUtils.isEmpty(papersType)) {
                    throw new BusinessException("证件类型不能为空");
                }

                if (StringUtils.isEmpty(papersNo)) {
                    throw new BusinessException("证件编号不能为空");
                }

                // if (cerSdate == null) {
                // throw new BusinessException("营业执照有效期开始日期不能为空");
                // }
                //
                // if (cerEdate == null) {
                // throw new BusinessException("营业执照有效期结束日期不能为空");
                // }

                if (StringUtils.isEmpty(entRegeditAddress)) {
                    throw new BusinessException("企业注册地址不能为空");
                }

                if (StringUtils.isEmpty(businessAddress)) {
                    throw new BusinessException("经营地址不能为空");
                }

                if (StringUtils.isEmpty(bankAccount)) {
                    throw new BusinessException("银行账号不能为空");
                }

                if (StringUtils.isEmpty(accountName)) {
                    throw new BusinessException("账户名称不能为空");
                }

                if (StringUtils.isEmpty(openBank)) {
                    throw new BusinessException("开户行不能为空");
                }

                if (StringUtils.isEmpty(openAccountProvince)) {
                    throw new BusinessException("开户省不能为空");
                }

                if (StringUtils.isEmpty(openingAccountCity)) {
                    throw new BusinessException("开户市不能为空");
                }

                if (StringUtils.isEmpty(openBranch)) {
                    throw new BusinessException("开户网点不能为空");
                }

                if (StringUtils.isEmpty(fixedTelephone)) {
                    throw new BusinessException("固定电电话不能为空");
                }

                if (StringUtils.isEmpty(accountOpenPermitUrl)) {
                    throw new BusinessException("开户许可证（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(bankAccountInfoCertUrl)) {
                    throw new BusinessException("银行账户信息证明（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(enterpriseBillingInformationUrl)) {
                    throw new BusinessException("企业开票信息（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(registeMoney)) {
                    throw new BusinessException("注册资金不能为空");
                }

                if (StringUtils.isEmpty(corpMode)) {
                    throw new BusinessException("企业性质不能为空");
                }
                if (StringUtils.isEmpty(employeeAmount)) {
                    throw new BusinessException("员工人数不能为空");
                }

                if (StringUtils.isEmpty(lastYearTurnover)) {
                    throw new BusinessException("上年度营业额不能为空");
                }
            }

        } else if (SystemConstant.CHANNEL_C03.equals(channel)) {// C03-青岛易付
            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_0.equals(userType) || SystemConstant.USER_TYPE_3.equals(userType)) {
                if (StringUtils.isEmpty(userName)) {
                    throw new BusinessException("用户名不能为空");
                }
                if (StringUtils.isEmpty(certificateType)) {
                    throw new BusinessException("证书类型不能为空");
                }

                if (StringUtils.isEmpty(legalRepresentativeName)) {
                    throw new BusinessException("法定代表人姓名不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateType)) {
                    throw new BusinessException("法定代表人证件类型不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateNo)) {
                    throw new BusinessException("法定代表人证件号码不能为空");
                }

                // if (StringUtils.isEmpty(adminName)) {
                // throw new BusinessException("管理员姓名不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminTelephone)) {
                // throw new BusinessException("管理员手机账号不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateType)) {
                // throw new BusinessException("管理员证件类型不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateNo)) {
                // throw new BusinessException("管理员证件号码不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminMail)) {
                // throw new BusinessException("管理员邮箱不能为空");
                // }

                if (StringUtils.isEmpty(businessLicenseUrl)) {
                    throw new BusinessException("营业执照（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(lrnLicenseUrl)) {
                    throw new BusinessException("法定代表人代表证照（影像资料）不能为空");
                }
                // if (StringUtils.isEmpty(adminLicenseUrl)) {
                // throw new BusinessException("管理员证照（影像资料）不能为空");
                // }

                if (StringUtils.isEmpty(entRegeditAddress)) {
                    throw new BusinessException("企业注册地址不能为空");
                }

                if (StringUtils.isEmpty(businessAddress)) {
                    throw new BusinessException("经营地址不能为空");
                }

                if (StringUtils.isEmpty(bankAccount)) {
                    throw new BusinessException("银行账号不能为空");
                }

                if (StringUtils.isEmpty(accountName)) {
                    throw new BusinessException("账户名称不能为空");
                }

                if (StringUtils.isEmpty(openBank)) {
                    throw new BusinessException("开户行不能为空");
                }

                if (StringUtils.isEmpty(openAccountProvince)) {
                    throw new BusinessException("开户省不能为空");
                }

                if (StringUtils.isEmpty(openingAccountCity)) {
                    throw new BusinessException("开户市不能为空");
                }

                if (StringUtils.isEmpty(openBranch)) {
                    throw new BusinessException("开户网点不能为空");
                }

                if (StringUtils.isEmpty(fixedTelephone)) {
                    throw new BusinessException("固定电电话不能为空");
                }

                if (StringUtils.isEmpty(accountOpenPermitUrl)) {
                    throw new BusinessException("开户许可证（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(bankAccountInfoCertUrl)) {
                    throw new BusinessException("银行账户信息证明（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(enterpriseBillingInformationUrl)) {
                    throw new BusinessException("企业开票信息（影像资料）不能为空");
                }
            }
        } else if (SystemConstant.CHANNEL_C04.equals(channel)) {// C04-财务信贷平台
            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_0.equals(userType) || SystemConstant.USER_TYPE_3.equals(userType)) {
                if (StringUtils.isEmpty(legalRepresentativeName)) {
                    throw new BusinessException("法定代表人姓名不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateType)) {
                    throw new BusinessException("法定代表人证件类型不能为空");
                }

                if (StringUtils.isEmpty(lrnCertificateNo)) {
                    throw new BusinessException("法定代表人证件号码不能为空");
                }

                // if (StringUtils.isEmpty(adminName)) {
                // throw new BusinessException("管理员姓名不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminTelephone)) {
                // throw new BusinessException("管理员手机账号不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateType)) {
                // throw new BusinessException("管理员证件类型不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminCertificateNo)) {
                // throw new BusinessException("管理员证件号码不能为空");
                // }
                //
                // if (StringUtils.isEmpty(adminMail)) {
                // throw new BusinessException("管理员邮箱不能为空");
                // }

                if (StringUtils.isEmpty(businessLicenseUrl)) {
                    throw new BusinessException("营业执照（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(lrnLicenseUrl)) {
                    throw new BusinessException("法定代表人代表证照（影像资料）不能为空");
                }
                // if (StringUtils.isEmpty(adminLicenseUrl)) {
                // throw new BusinessException("管理员证照（影像资料）不能为空");
                // }

                if (StringUtils.isEmpty(papersType)) {
                    throw new BusinessException("证件类型不能为空");
                }

                if (StringUtils.isEmpty(papersNo)) {
                    throw new BusinessException("证件编号不能为空");
                }

                // if (cerSdate == null) {
                // throw new BusinessException("营业执照有效期开始日期不能为空");
                // }
                //
                // if (cerEdate == null) {
                // throw new BusinessException("营业执照有效期结束日期不能为空");
                // }
            }

            // 用户类型,0-企业用户，1-港内员工用户，2-个人用户，3-企业员工用户
            if (SystemConstant.USER_TYPE_2.equals(userType)) {
                if (StringUtils.isEmpty(bankAccount)) {
                    throw new BusinessException("银行账号不能为空");
                }

                if (StringUtils.isEmpty(bankOpenBank)) {
                    throw new BusinessException("银行开户行不能为空");
                }

                if (StringUtils.isEmpty(occupation)) {
                    throw new BusinessException("职业不能为空");
                }

                if (StringUtils.isEmpty(gender)) {
                    throw new BusinessException("民族不能为空");
                }

                if (StringUtils.isEmpty(nation)) {
                    throw new BusinessException("性别不能为空");
                }

                if (StringUtils.isEmpty(livingConditions)) {
                    throw new BusinessException("居住状况不能为空");
                }

                if (StringUtils.isEmpty(homeAddress)) {
                    throw new BusinessException("家庭住址不能为空");
                }

                if (personalAnnualIncome == null) {
                    throw new BusinessException("个人年收入");
                }

                if (StringUtils.isEmpty(incomeSource)) {
                    throw new BusinessException("收入来源不能为空");
                }

                if (StringUtils.isEmpty(entityName)) {
                    throw new BusinessException("单位名称不能为空");
                }

                if (StringUtils.isEmpty(unitNature)) {
                    throw new BusinessException("单位性质不能为空");
                }

                if (StringUtils.isEmpty(workingYears)) {
                    throw new BusinessException("本单位工作年限不能为空");
                }
                if (payDay == null) {
                    throw new BusinessException("工资发放日不能为空");
                }
                if (StringUtils.isEmpty(unitAddress)) {
                    throw new BusinessException("单位地址不能为空");
                }

                if (StringUtils.isEmpty(personalIdentificationUrl)) {
                    throw new BusinessException("个人身份证明（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(bankCardInfoUrl)) {
                    throw new BusinessException("银行卡信息（影像资料）不能为空");
                }

                if (StringUtils.isEmpty(maritalStatus)) {
                    throw new BusinessException("婚姻状况不能为空");
                }

                if (SystemConstant.MARITAL_STATUS_0.equals(maritalStatus)) {// 已婚
                    if (StringUtils.isEmpty(spouseName)) {
                        throw new BusinessException("配偶姓名不能为空");
                    }

                    if (StringUtils.isEmpty(spouseCertificateType)) {
                        throw new BusinessException("证件类型不能为空");
                    }
                    if (StringUtils.isEmpty(spouseCertificateNo)) {
                        throw new BusinessException("证件号码不能为空");
                    }
                    if (StringUtils.isEmpty(spouseTelephone)) {
                        throw new BusinessException("手机号码不能为空");
                    }
                    if (!CommUtils.isPhone(spouseTelephone)) {
                        throw new BusinessException(ErrorMessageConstant.ECUC0019_MESSAGE,
                                ErrorMessageConstant.ECUC0019_CODE);
                    }
                }
            }
        }
    }

    /**
     * 获取邀请码，同时校验在ur_user_base_information是否重复。
     *
     * @return
     */
    private String getInvitationCodeString() {
        String invitationCode = null;
        Integer integer = null;
        do {
            invitationCode = CommUtils.getInviteCode();
            QueryWrapper<UserBaseInformation> queryWrapperUbi = new QueryWrapper<>();
            queryWrapperUbi.eq("invite_code", invitationCode);
            integer = this.getBaseMapper().selectCount(queryWrapperUbi);
        } while (integer != null && integer > 0);
        return invitationCode;
    }

    /**
     * 获取邀请码，同时校验在ur_invitee_information是否重复。
     *
     * @return
     */
    private String getUniqueInvitationCodeString() {
        String invitationCode = null;
        Integer integer = null;
        do {
            invitationCode = CommUtils.getInviteCode();
            QueryWrapper<InviteeInformation> queryWrapperUbi = new QueryWrapper<>();
            queryWrapperUbi.eq("invite_code", invitationCode);
            integer = inviteeInformationMapper.selectCount(queryWrapperUbi);
        } while (integer != null && integer > 0);
        return invitationCode;
    }

    // add by gaole.dai 2019-12-31 企业注册以后在邀请制渠道补全被邀请码 begin
    public String supplementTheInvitationCode(SupplementInvitationCode requestObject) throws Exception {
        // 声明变量 begin
        // 邀请人id
        Integer userId = requestObject.getUserId();
        // 渠道
        String channel = requestObject.getChannel();
        // 被邀请客户信息-联系人手机号不能为空
        String oppositeContactPhone = requestObject.getOppositeContactPhone();
        // 被邀请客户信息-联系人不能为空
        String oppositeContactPerson = requestObject.getOppositeContactPerson();
        // 被邀请客户信息-企业名称不能为空
        String oppositeName = requestObject.getOppositeName();
        // 被邀请客户信息-证件号
        String oppositePapersNo = requestObject.getOppositePapersNo();
        // 邀请码
        String inviteCode = requestObject.getInviteCode();
        // 声明变量 end
        // if (!generalService.determineIfItIsAnInvitationSystem(channel)) {
        // throw new BusinessException(ErrorMessageConstant.ECUC0040_MESSAGE, ErrorMessageConstant.ECUC0040_CODE);
        // }
        // 校验用户是否存在
        UserBaseInformation userBaseInformation = generalService.whetherTheUserHasAGate(userId);
        // 抽出邀请制闸口
        generalService.invitationGate(channel, oppositeName, oppositeContactPerson, oppositeContactPhone, inviteCode,
                oppositePapersNo, userBaseInformation.getUserType());
        if (StringUtils.isNotEmpty(userBaseInformation.getInviteCode())
                && userBaseInformation.getInviteCode().equals(inviteCode)) {
            throw new BusinessException(ErrorMessageConstant.ECUC0044_MESSAGE, ErrorMessageConstant.ECUC0044_CODE);
        }
        userBaseInformation.setGmtModified(LocalDateTime.now());
        userBaseInformation.setModifiedBy(requestObject.getOperationUserId());
        this.getBaseMapper().updateById(userBaseInformation);
        // 2021-06-30 新增可补录自然人 syf
        if (SystemConstant.USER_TYPE_2.equals(userBaseInformation.getUserType())) {
            LambdaQueryWrapper<NaturalPersonBaseInformation> queryWrapperNBI =
                    new LambdaQueryWrapper<NaturalPersonBaseInformation>();
            queryWrapperNBI.eq(NaturalPersonBaseInformation::getUserId, userId);
            NaturalPersonBaseInformation naturalPersonBaseInformation =
                    naturalPersonBaseInformationMapper.selectOne(queryWrapperNBI);
            naturalPersonBaseInformation.setGmtModified(LocalDateTime.now());
            naturalPersonBaseInformation.setModifiedBy(requestObject.getOperationUserId());
            naturalPersonBaseInformation.setEnteredInviteCode(inviteCode);
            naturalPersonBaseInformationMapper.update(naturalPersonBaseInformation, queryWrapperNBI);
        } else {
            LambdaQueryWrapper<EnterpriseBasicInfo> queryWrapperEBI = new LambdaQueryWrapper<EnterpriseBasicInfo>();
            queryWrapperEBI.eq(EnterpriseBasicInfo::getUserId, userId);
            EnterpriseBasicInfo enterpriseBasicInfo = enterpriseBasicInfoMapper.selectOne(queryWrapperEBI);
            enterpriseBasicInfo.setGmtModified(LocalDateTime.now());
            enterpriseBasicInfo.setModifiedBy(requestObject.getOperationUserId());
            enterpriseBasicInfo.setEnteredInviteCode(inviteCode);
            enterpriseBasicInfoMapper.update(enterpriseBasicInfo, queryWrapperEBI);
        }
        // 补录完邀请码后，将邀请码失效状态置为1
        updateExpireStateForSupplement(requestObject);

        return SystemConstant.SYSTEM_SUCCESS;
    }
    // add by gaole.dai 2019-12-31 企业注册以后在邀请制渠道补全被邀请码 end

    public InviteeInformationDTO queryInviteeInformation(QueryInviteeInformationReq requestObject) {
        InviteeInformation inviteeInformation = null;
        InviteeInformationDTO inviteeInformationDTO = null;
        LambdaQueryWrapper<InviteeInformation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InviteeInformation::getInviteCode, requestObject.getInviteCode());
        List<InviteeInformation> inviteeInformationList = inviteeInformationMapper.selectList(queryWrapper);
        if (inviteeInformationList.size() > 0) {
            if (SystemConstant.INVITE_CODE_TYPE_0.equals(inviteeInformationList.get(0).getInviteCodeType())) {
                throw new BusinessException(ErrorMessageConstant.ECUC0049_MESSAGE, ErrorMessageConstant.ECUC0049_CODE);
            }

            // Add By Liwq On 2020-11-26 Start
            // 是动态邀请码，在邀请信息表里，是唯一的；
            // 注意：因为只有注册完、或者补录邀请码后，才会将表里的失效状态置为1；如果一直没有注册、或者补录邀请码，
            // 那么状态将一直是0，可能不对；我们在查询的时候，先更新下最新状态值，再将最新状态返回；
            inviteeInformation = inviteeInformationList.get(0);
            Boolean expireFlag = judgeExpireOrNot(inviteeInformation.getEndTime());
            if (expireFlag) {
                inviteeInformation.setState(SystemConstant.UR_INVITEE_INFORMATION_STATE_1);
                inviteeInformationMapper.updateById(inviteeInformation);
            }
            // Add By Liwq On 2020-11-26 End

            inviteeInformationDTO = mapper.map(inviteeInformation, InviteeInformationDTO.class);
        }
        return inviteeInformationDTO;
    }

    /**
     * @param requestObj 绑定钉钉账号
     * @return
     */
    public String bindDingTalk(BindDingDingReq requestObj) {
        UserBaseInformation userBaseInformation = userBaseInformationMapper.selectById(requestObj.getUserId());
        UserBaseInformationHistory userBaseInformationHistory =
                dozerBeanMapper.map(userBaseInformation, UserBaseInformationHistory.class);
        userBaseInformationHistoryMapper.insert(userBaseInformationHistory);
        userBaseInformation.setDingtalkUserid(requestObj.getDingtalkUserid());
        userBaseInformation.setGmtModified(LocalDateTime.now());
        userBaseInformation.setModifiedBy(requestObj.getOperationUserId());
        userBaseInformationMapper.updateById(userBaseInformation);
        return SystemConstant.SYSTEM_SUCCESS;
    }

    public List<FactorsModifyRecordDto> queryFactorsModifyRecord(QueryFactorsModifyRecordReq requestObject) {
        IPage<FactorsModifyRecordDto> page = null;
        List<FactorsModifyRecordDto> records = null;
        ArrayList<FactorsModifyRecordDto> factorsModifyRecordDtos = new ArrayList<>();
        PagerInfo pagerInfo = requestObject.getPagerInfo();
        Page<FactorsModifyRecord> factorsModifyRecordPage = new Page<>(pagerInfo.getPageNum(), pagerInfo.getPageSize());
        List<Integer> userIdList = new ArrayList<>();
        if(StringUtils.isNotBlank(requestObject.getUserName())){
            userIdList = getUserIdByName(requestObject.getUserName());
        }
        page = factorsModifyRecordMapper.queryFactorsModifyRecord(factorsModifyRecordPage, requestObject.getUserId(),requestObject.getUserType(),requestObject.getModifyChannel(),requestObject.getModifyFormat(),requestObject.getModifyTimeStart(),requestObject.getModifyTimeEnd(),userIdList);
        records = page.getRecords();
        if (records != null && records.size() == 0) {
            return factorsModifyRecordDtos;
        }
        for (FactorsModifyRecordDto obj : records) {
            obj.setUserName(getUserNameById(obj.getUserId()));
            obj.setModifyFormatName(getUserNameById(obj.getModifyFormat()));
            obj.setModifyByName(getUserNameById(obj.getModifyBy()));
            if(StringUtils.isNotBlank(obj.getAuthorizedFormats())){
                List<String> authorizedFormats =
                        Arrays.asList(obj.getAuthorizedFormats().split(queryChannelSplitFlag));
                StringBuffer formatNames = new StringBuffer();
                for(int i=0;i<authorizedFormats.size();i++) {
                    if (i != 0) {
                        formatNames.append("，");
                    }
                    formatNames.append(getUserNameById(Integer.valueOf(authorizedFormats.get(i))));
                }
                obj.setAuthorizedFormatsName(formatNames.toString());
            }
            factorsModifyRecordDtos.add(obj);
        }
        pagerInfo.setTotal(page.getTotal());
        return factorsModifyRecordDtos;
    }
    //根据userid获取用户名
    public String getUserNameById(Integer userId){
        LambdaQueryWrapper<UserBaseInformation> queryUBI = new LambdaQueryWrapper<>();
        queryUBI.eq(UserBaseInformation::getUserId, userId);
        queryUBI.orderByDesc(UserBaseInformation::getGmtModified);
        List<UserBaseInformation> userBaseInformationList = userBaseInformationMapper.selectList(queryUBI);
        if (userBaseInformationList.size() > 0) {
            String userType = userBaseInformationList.get(0).getUserType();
            if (SystemConstant.USER_TYPE_0.equals(userType)) {
                LambdaQueryWrapper<EnterpriseBasicInfo> queryEBI = new LambdaQueryWrapper<>();
                queryEBI.eq(EnterpriseBasicInfo::getUserId, userId);
                queryEBI.orderByDesc(EnterpriseBasicInfo::getGmtModified);
                List<EnterpriseBasicInfo> enterpriseBasicInfoList = enterpriseBasicInfoMapper.selectList(queryEBI);
                if (enterpriseBasicInfoList.size() > 0) {
                    return enterpriseBasicInfoList.get(0).getCompanyName();
                }
            } else if (SystemConstant.USER_TYPE_1.equals(userType)) {
                LambdaQueryWrapper<EmployeeInformation> queryEI = new LambdaQueryWrapper<>();
                queryEI.eq(EmployeeInformation::getUserId, userId);
                queryEI.orderByDesc(EmployeeInformation::getGmtModified);
                List<EmployeeInformation> employeeInformationList = employeeInformationMapper.selectList(queryEI);
                if (employeeInformationList.size() > 0) {
                    return employeeInformationList.get(0).getUserName();
                }
            } else if (SystemConstant.USER_TYPE_2.equals(userType)) {
                LambdaQueryWrapper<NaturalPersonBaseInformation> queryNBI = new LambdaQueryWrapper<>();
                queryNBI.eq(NaturalPersonBaseInformation::getUserId, userId);
                queryNBI.orderByDesc(NaturalPersonBaseInformation::getGmtModified);
                List<NaturalPersonBaseInformation> naturalPersonBaseInformationList = naturalPersonBaseInformationMapper.selectList(queryNBI);
                if (naturalPersonBaseInformationList.size() > 0) {
                    return naturalPersonBaseInformationList.get(0).getUserName();
                }
            } else if (SystemConstant.USER_TYPE_3.equals(userType)) {
                LambdaQueryWrapper<EnterpriseUserInfo> queryEUI = new LambdaQueryWrapper<>();
                queryEUI.eq(EnterpriseUserInfo::getUserId, userId);
                queryEUI.orderByDesc(EnterpriseUserInfo::getGmtModified);
                List<EnterpriseUserInfo> enterpriseUserInfoList = enterpriseUserInfoMapper.selectList(queryEUI);
                if (enterpriseUserInfoList.size() > 0) {
                    return enterpriseUserInfoList.get(0).getUserName();
                }
            } else if (SystemConstant.USER_TYPE_4.equals(userType) || SystemConstant.USER_TYPE_5.equals(userType)) {
                LambdaQueryWrapper<OrganizationalStructure> queryOS = new LambdaQueryWrapper<>();
                queryOS.eq(OrganizationalStructure::getOrganizationalId, userId);
                queryOS.orderByDesc(OrganizationalStructure::getGmtModified);
                List<OrganizationalStructure> organizationalStructureList = organizationalStructureMapper.selectList(queryOS);
                if (organizationalStructureList.size() > 0) {
                    return organizationalStructureList.get(0).getOrganizationalName();
                }
            }
            return null;
        }
        return null;
    }
    //根据用户名获取用户id(企业、自然人)
    public List<Integer> getUserIdByName(String userName){
        //企业
        List<Integer> userIdList = new ArrayList<>();
        LambdaQueryWrapper<EnterpriseBasicInfo> queryEBI = new LambdaQueryWrapper<>();
        queryEBI.like(EnterpriseBasicInfo::getCompanyName, userName);
        List<EnterpriseBasicInfo> enterpriseBasicInfoList = enterpriseBasicInfoMapper.selectList(queryEBI);
        for(int i=0;i<enterpriseBasicInfoList.size();i++){
            userIdList.add(enterpriseBasicInfoList.get(i).getUserId());
        }
        //自然人
        LambdaQueryWrapper<NaturalPersonBaseInformation> queryNBI = new LambdaQueryWrapper<>();
        queryNBI.like(NaturalPersonBaseInformation::getUserName, userName);
        List<NaturalPersonBaseInformation> naturalPersonBaseInformationList = naturalPersonBaseInformationMapper.selectList(queryNBI);
        for(int i=0;i<naturalPersonBaseInformationList.size();i++){
            userIdList.add(naturalPersonBaseInformationList.get(i).getUserId());
        }
        return userIdList;
    }
}
